home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 80 / CD Actual 80 Julio-Agosto 2003.iso / Linux / LinuxGazette / lg / issue11 / misc / sysklog.patch
Encoding:
Text File  |  2002-08-14  |  72.0 KB  |  2,548 lines

  1.  
  2. From greg@wind.rmcc.com Mon Sep  9 15:50:23 1996
  3. Date: Mon, 09 Sep 1996 07:14:37 -0500 (CDT)
  4. From: "G.W. Wettstein" <greg@wind.rmcc.com>
  5. To: "John M. Fisk" <fiskjm@ctrvax.Vanderbilt.Edu>
  6. Subject: Re: sysklogd fix/patch
  7.  
  8. On Sep 7,  2:11pm, "John M. Fisk" wrote:
  9. } Subject: sysklogd fix/patch
  10.  
  11. > Greg,
  12.  
  13. Good morning John, thanks for the ntoe.
  14.  
  15. > Sorry to bother you but I've been unsuccessful finding an answer to a
  16. > problem I've been having (and apparently quite a few others as well) with
  17. > syslogd and Slackware '96.
  18. > I just read a post to comp.os.linux.setup that stated that the sysklogd
  19. > devel team had issued an updated version or patch that corrected a problem
  20. > with syslogd which caused it to dump core -- the problem having something
  21. > to do with the networking setup used by Slackware.
  22. > Could you point me to where I could FTP the updated sources or pick up a
  23. > patch for the current sources?
  24.  
  25. Even better the fixes are enclosed below... :-)
  26.  
  27. The following set of patches are what I just announced last Friday.
  28. Give them a try and let me know if the problems are fixed.
  29.  
  30. > Thanks so much!
  31. > Best Wishes,
  32.  
  33. No problem, hopefully they will make things better.  Have a pleasant
  34. remainder of the week.
  35.  
  36. > ____________________________________________________________John M. Fisk
  37.  
  38. Greg
  39.  
  40. Cut here to begin separating patch 1. -------------------------------------
  41. diff -u --new-file --recursive v1.3/sysklogd-1.3/Makefile sysklogd-1.3/Makefile
  42. --- v1.3/sysklogd-1.3/Makefile    Mon Feb 19 15:18:23 1996
  43. +++ sysklogd-1.3/Makefile    Sun Mar 31 06:11:04 1996
  44. @@ -3,11 +3,10 @@
  45.  CC= gcc
  46.  #CFLAGS= -g -DSYSV -Wall
  47.  #LDFLAGS= -g
  48. -CFLAGS= -O6 -DSYSV -fomit-frame-pointer -Wall
  49. -LDFLAGS= -s -N
  50. +CFLAGS= -O2 -DSYSV -fomit-frame-pointer -Wall -fno-strength-reduce
  51. +LDFLAGS= -s
  52.  
  53. -# Look where your install program is
  54. -#
  55. +# Look where your install program is.
  56.  INSTALL = /usr/bin/install
  57.  BINDIR = /usr/sbin
  58.  MANDIR = /usr/man
  59. @@ -17,6 +16,13 @@
  60.  # to try uncommenting the following define.
  61.  # LIBS = /usr/lib/libresolv.a
  62.  
  63. +# A patch was forwarded which provided support for sysklogd under
  64. +# the ALPHA.  This patch included a reference to a library which may be
  65. +# specific to the ALPHA.  If you are attempting to build this package under
  66. +# an ALPHA and linking fails with unresolved references please try
  67. +# uncommenting the following define.
  68. +# LIBS = ${LIBS} -linux
  69. +
  70.  # Define the following to impart start-up delay in klogd.  This is
  71.  # useful if klogd is started simultaneously or in close-proximity to syslogd.
  72.  # KLOGD_START_DELAY = -DKLOGD_DELAY=5
  73. @@ -54,7 +60,7 @@
  74.      ${CC} ${LDFLAGS} -o syslogd syslogd.o pidfile.o ${LIBS}
  75.  
  76.  klogd:    klogd.o syslog.o pidfile.o ksym.o
  77. -    ${CC} ${LDFLAGS} -o klogd klogd.o syslog.o pidfile.o ksym.o
  78. +    ${CC} ${LDFLAGS} -o klogd klogd.o syslog.o pidfile.o ksym.o ${LIBS}
  79.  
  80.  syslog_tst: syslog_tst.o
  81.      ${CC} ${LDFLAGS} -o syslog_tst syslog_tst.o
  82. @@ -75,17 +81,17 @@
  83.      ${CC} ${CFLAGS} -c syslog_tst.c
  84.  
  85.  clean:
  86. -    rm -f *.o *.log *~ *.orig;
  87. +    rm -f *.o *.log *~ *.orig
  88.  
  89.  clobber: clean
  90. -    rm -f syslogd klogd syslog_tst TAGS;
  91. +    rm -f syslogd klogd syslog_tst TAGS
  92.  
  93.  install_exec: syslogd klogd
  94. -    ${INSTALL} -m 500 -s syslogd ${BINDIR}/syslogd;
  95. -    ${INSTALL} -m 500 -s klogd ${BINDIR}/klogd;
  96. +    ${INSTALL} -m 500 -s syslogd ${BINDIR}/syslogd
  97. +    ${INSTALL} -m 500 -s klogd ${BINDIR}/klogd
  98.  
  99.  install_man:
  100.      ${INSTALL} -o ${MAN_OWNER} -g ${MAN_OWNER} -m 644 sysklogd.8 ${MANDIR}/man8/sysklogd.8
  101.      ${INSTALL} -o ${MAN_OWNER} -g ${MAN_OWNER} -m 644 syslogd.8 ${MANDIR}/man8/syslogd.8
  102.      ${INSTALL} -o ${MAN_OWNER} -g ${MAN_OWNER} -m 644 syslog.conf.5 ${MANDIR}/man5/syslog.conf.5
  103. -    ${INSTALL} -o ${MAN_OWNER} -g ${MAN_OWNER} -m 644 klogd.8 ${MANDIR}/MAN8/klogd.8
  104. +    ${INSTALL} -o ${MAN_OWNER} -g ${MAN_OWNER} -m 644 klogd.8 ${MANDIR}/man8/klogd.8
  105. diff -u --new-file --recursive v1.3/sysklogd-1.3/NEWS sysklogd-1.3/NEWS
  106. --- v1.3/sysklogd-1.3/NEWS    Fri Dec 15 15:06:25 1995
  107. +++ sysklogd-1.3/NEWS    Sun Mar 31 06:21:14 1996
  108. @@ -1,3 +1,35 @@
  109. +Version 1.3 Patch Level 1
  110. +
  111. +General. ------------------------------------------------------------------
  112. +Cleanups in the Makefile.
  113. +
  114. +Patches to support compilation in the ALPHA environment.  I have not
  115. +been able to test these personally so if anyone has any feedback I
  116. +would be interested in hearing from the Linux ALPHA community.
  117. +
  118. +Spelling and grammar corrections in the man pages.
  119. +
  120. +
  121. +syslogd ------------------------------------------------------------------
  122. +Patch to fix parsing of hostnames in syslogd.c.
  123. +
  124. +The return value of gethostbyname is now properly checked.  This should
  125. +fix the problems with core dumps when name resolution failed.
  126. +
  127. +Bounds error fixed when setting the file descriptors for UNIX domain
  128. +sockets.
  129. +
  130. +
  131. +klogd ---------------------------------------------------------------------
  132. +Error checking and reporting enhanced.  I have a couple of reports
  133. +that klogd is experiencing errors when reading the /proc filesystem.
  134. +Any additional information would be appreciated.
  135. +
  136. +The sys_syslog function has been renamed to ksyslog.  This was in a
  137. +set patches for ALPHA support so I am assuming that this is necessary
  138. +for that environment
  139. +
  140. +
  141.  Version 1.3 
  142.  
  143.  Numerous changes, performance enhancements, code cleanups and bug fixes.
  144. diff -u --new-file --recursive v1.3/sysklogd-1.3/klogd.c sysklogd-1.3/klogd.c
  145. --- v1.3/sysklogd-1.3/klogd.c    Sat Feb 17 14:02:54 1996
  146. +++ sysklogd-1.3/klogd.c    Tue Mar 19 11:50:43 1996
  147. @@ -159,8 +159,10 @@
  148.  
  149.  #define __LIBRARY__
  150.  #include <linux/unistd.h>
  151. -#define __NR_sys_syslog __NR_syslog
  152. -_syscall3(int,sys_syslog,int, type, char *, buf, int, len);
  153. +#ifndef __alpha__
  154. +# define __NR_ksyslog __NR_syslog
  155. +_syscall3(int,ksyslog,int, type, char *, buf, int, len);
  156. +#endif
  157.  
  158.  #define LOG_BUFFER_SIZE 4096
  159.  #define LOG_LINE_LENGTH 1024
  160. @@ -191,7 +193,7 @@
  161.  
  162.  
  163.  /* Function prototypes. */
  164. -extern int sys_syslog(int type, char *buf, int len);
  165. +extern int ksyslog(int type, char *buf, int len);
  166.  static void CloseLogSrc(void);
  167.  extern void restart(int sig);
  168.  extern void stop_logging(int sig);
  169. @@ -209,14 +211,14 @@
  170.  
  171.  {
  172.      /* Turn on logging of messages to console. */
  173. -      sys_syslog(7, NULL, 0);
  174. +      ksyslog(7, NULL, 0);
  175.    
  176.          /* Shutdown the log sources. */
  177.      switch ( logsrc )
  178.      {
  179.          case kernel:
  180. -        sys_syslog(0, 0, 0);
  181. -        Syslog(LOG_INFO, "Kernel logging (sys_syslog) stopped.");
  182. +        ksyslog(0, 0, 0);
  183. +        Syslog(LOG_INFO, "Kernel logging (ksyslog) stopped.");
  184.          break;
  185.              case proc:
  186.          close(kmsg);
  187. @@ -326,7 +328,7 @@
  188.  
  189.  
  190.      /* Set level of kernel console messaging.. */
  191. -    if ( (sys_syslog(8, NULL, console_log_level) < 0) && \
  192. +    if ( (ksyslog(8, NULL, console_log_level) < 0) && \
  193.           (errno == EINVAL) )
  194.      {
  195.          /*
  196. @@ -337,7 +339,7 @@
  197.           */
  198.          Syslog(LOG_WARNING, "Cannot set console log level - disabling "
  199.                    "console output.");
  200. -        sys_syslog(6, NULL, 0);
  201. +        ksyslog(6, NULL, 0);
  202.      }
  203.      
  204.  
  205. @@ -349,16 +351,17 @@
  206.          ((stat(_PATH_KLOG, &sb) < 0) && (errno == ENOENT)) )
  207.      {
  208.            /* Initialize kernel logging. */
  209. -          sys_syslog(1, NULL, 0);
  210. -        Syslog(LOG_INFO, "klogd %s-%s, log source = sys_syslog "
  211. +          ksyslog(1, NULL, 0);
  212. +        Syslog(LOG_INFO, "klogd %s-%s, log source = ksyslog "
  213.                 "started.", VERSION, PATCHLEVEL);
  214.          return(kernel);
  215.      }
  216.      
  217.      if ( (kmsg = open(_PATH_KLOG, O_RDONLY)) < 0 )
  218.      {
  219. -        fputs("klogd: Cannot open proc file system.", stderr);
  220. -        sys_syslog(7, NULL, 0);
  221. +        fprintf(stderr, "klogd: Cannot open proc file system, " \
  222. +            "%d - %s.\n", errno, strerror(errno));
  223. +        ksyslog(7, NULL, 0);
  224.          exit(1);
  225.      }
  226.  
  227. @@ -517,12 +520,12 @@
  228.       * messages into this fresh buffer.
  229.       */
  230.      memset(log_buffer, '\0', sizeof(log_buffer));
  231. -    if ( (rdcnt = sys_syslog(2, log_buffer, sizeof(log_buffer))) < 0 )
  232. +    if ( (rdcnt = ksyslog(2, log_buffer, sizeof(log_buffer))) < 0 )
  233.      {
  234.          if ( errno == EINTR )
  235.              return;
  236. -        fprintf(stderr, "Error return from sys_sycall: %d - %s\n", \
  237. -            errno, strerror(errno));
  238. +        fprintf(stderr, "klogd: Error return from sys_sycall: " \
  239. +            "%d - %s\n", errno, strerror(errno));
  240.      }
  241.      
  242.      LogLine(log_buffer, rdcnt);
  243. @@ -546,7 +549,8 @@
  244.      {
  245.          if ( errno == EINTR )
  246.              return;
  247. -        Syslog(LOG_ERR, "Cannot read proc file system.");
  248. +        Syslog(LOG_ERR, "Cannot read proc file system: %d - %s.", \
  249. +               errno, strerror(errno));
  250.      }
  251.      
  252.      LogLine(log_buffer, rdcnt);
  253. @@ -687,8 +691,8 @@
  254.              output_file = stdout;
  255.          else if ( (output_file = fopen(output, "w")) == (FILE *) 0 )
  256.          {
  257. -            fprintf(stderr, "klogd: Cannot open output file %s - "\
  258. -                "%s\n", output, strerror(errno));
  259. +            fprintf(stderr, "klogd: Cannot open output file " \
  260. +                "%s - %s\n", output, strerror(errno));
  261.              return(1);
  262.          }
  263.      }
  264. diff -u --new-file --recursive v1.3/sysklogd-1.3/sysklogd.8 sysklogd-1.3/sysklogd.8
  265. --- v1.3/sysklogd-1.3/sysklogd.8    Sat Feb 17 14:02:54 1996
  266. +++ sysklogd-1.3/sysklogd.8    Tue Mar  5 12:52:59 1996
  267. @@ -39,7 +39,7 @@
  268.  .BR syslogd (8)
  269.  derived from the
  270.  stock BSD sources.  Support for kernel logging is provided by the
  271. -.BR syslogd (8)
  272. +.BR klogd (8)
  273.  utility which allows kernel logging to be conducted in either a
  274.  standalone fashion or as a client of syslogd.
  275.  
  276. @@ -91,7 +91,7 @@
  277.  .TP
  278.  .BI "\-l " "hostlist"
  279.  Specify a hostname that should be logged only with its simple hostname
  280. -and not the the fqdn. Multiple hosts may be specified using the colon
  281. +and not the fqdn. Multiple hosts may be specified using the colon
  282.  (``:'') separator.
  283.  .TP
  284.  .BI "\-m " "interval"
  285. @@ -195,8 +195,8 @@
  286.  .PP
  287.  Under the new scheme this behavior remains the same.  The difference
  288.  is the addition of four new specifiers, the asterisk (\fB*\fR)
  289. -wildcard the equation sign (\fB=\fR), the exclamation mark
  290. -(\fB!\fR) and the minus sign (\fB-\fR).
  291. +wildcard, the equation sign (\fB=\fR), the exclamation mark
  292. +(\fB!\fR), and the minus sign (\fB-\fR).
  293.  
  294.  The \fB*\fR specifies that all messages for the
  295.  specified facility are to be directed to the destination.  Note that
  296. @@ -215,7 +215,7 @@
  297.  .IP
  298.  .nf
  299.      # Sample syslog.conf
  300. -    daemon.=debug            /usr/adm/debug
  301. +    *.=debug            /usr/adm/debug
  302.  .fi
  303.  .PP
  304.  .\" The \fB!\fR as the first character of a priority inverts the above
  305. @@ -456,11 +456,11 @@
  306.  .SH DEBUGGING
  307.  When debugging is turned on using
  308.  .B "\-d"
  309. -option the
  310. +option then
  311.  .B syslogd
  312. -will very verbose by writing much of what it does on stdout. Whenever
  313. +will be very verbose by writing much of what it does on stdout. Whenever
  314.  the configuration file is reread and re-parsed you'll see a tabular,
  315. -corresponding on the internal data structure. This tabular consists of
  316. +corresponding to the internal data structure. This tabular consists of
  317.  four fields:
  318.  .TP
  319.  .I number
  320. @@ -489,7 +489,7 @@
  321.  This field shows additional arguments to the actions in the last
  322.  field. For file-logging this is the filename for the logfile; for
  323.  user-logging this is a list of users; for remote logging this is the
  324. -the hostname of the machine to log to; for console-logging this is the
  325. +hostname of the machine to log to; for console-logging this is the
  326.  used console; for tty-logging this is the specified tty; wall has no
  327.  additional arguments.
  328.  .SH FILES
  329. diff -u --new-file --recursive v1.3/sysklogd-1.3/syslogd.c sysklogd-1.3/syslogd.c
  330. --- v1.3/sysklogd-1.3/syslogd.c    Mon Feb 19 09:24:33 1996
  331. +++ sysklogd-1.3/syslogd.c    Fri Mar  8 11:19:25 1996
  332. @@ -715,9 +715,15 @@
  333.           * should return the simple hostname or the fqdn. A
  334.           * good piece of software should be aware of both and
  335.           * we want to distribute good software.  Joey
  336. +         *
  337. +         * Good software also always checks its return values...
  338. +         * If syslogd starts up before DNS is up & /etc/hosts
  339. +         * doesn't have LocalHostName listed, gethostbyname will
  340. +         * return NULL. 
  341.           */
  342.          hent = gethostbyname(LocalHostName);
  343. -        sprintf(LocalHostName, "%s", hent->h_name);
  344. +        if ( hent )
  345. +            sprintf(LocalHostName, "%s", hent->h_name);
  346.          if ( (p = index(LocalHostName, '.')) )
  347.          {
  348.              *p++ = '\0';
  349. @@ -890,7 +896,7 @@
  350.                      dprintf("%d ", nfds);
  351.              dprintf("\n");
  352.          }
  353. -        for (fd= 0; fd <= FD_SETSIZE; ++fd)
  354. +        for (fd= 0; fd < FD_SETSIZE; ++fd)
  355.            if ( FD_ISSET(fd, &readfds) && FD_ISSET(fd, &unixm) ) {
  356.              dprintf("Message from UNIX socket #%d.\n", fd);
  357.              memset(line, '\0', sizeof(line));
  358. @@ -979,9 +985,8 @@
  359.  crunch_list(list)
  360.      char *list;
  361.  {
  362. -    int count;
  363. -    int i;
  364. -    char *p;
  365. +    int count, i;
  366. +    char *p, *q;
  367.      char **result = NULL;
  368.  
  369.      p = list;
  370. @@ -1012,15 +1017,15 @@
  371.       * so we don't have to care about this.
  372.       */
  373.      count = 0;
  374. -    while ((i=(int)index(p, LIST_DELIMITER))) {
  375. -        if ((result[count] = \
  376. -             (char *)malloc(sizeof(char) * i - (int)p +1)) == NULL) {
  377. +    while ((q=index(p, LIST_DELIMITER))) {
  378. +        result[count] = (char *) malloc((q - p + 1) * sizeof(char));
  379. +        if (result[count] == NULL) {
  380.              printf ("Sorry, can't get enough memory, exiting.\n");
  381.              exit(0);
  382.          }
  383. -        strncpy(result[count],p, i - (int)p);
  384. -        result[count][i - (int)p] = '\0';
  385. -        p = (char *)i;p++;
  386. +        strncpy(result[count], p, q - p);
  387. +        result[count][q - p] = '\0';
  388. +        p = q; p++;
  389.          count++;
  390.      }
  391.      if ((result[count] = \
  392. diff -u --new-file --recursive v1.3/sysklogd-1.3/version.h sysklogd-1.3/version.h
  393. --- v1.3/sysklogd-1.3/version.h    Tue Feb 27 15:48:42 1996
  394. +++ sysklogd-1.3/version.h    Sun Mar 31 05:58:48 1996
  395. @@ -1,2 +1,2 @@
  396.  #define VERSION "1.3"
  397. -#define PATCHLEVEL "0"
  398. +#define PATCHLEVEL "1"
  399. Cut here to complete separating patch 1. ----------------------------------
  400.  
  401. Cut here to begin separating patch 2. -------------------------------------
  402. diff -u --new-file --recursive v1.3-1/sysklogd-1.3/MANIFEST sysklogd-1.3/MANIFEST
  403. --- v1.3-1/sysklogd-1.3/MANIFEST    Sun Mar 31 11:19:05 1996
  404. +++ sysklogd-1.3/MANIFEST    Thu May  2 15:21:49 1996
  405. @@ -17,6 +17,9 @@
  406.  ksym.c:        Source module for the kernel log daemon which implements
  407.          kernel numeric address to symbol translations.
  408.  
  409. +ksym_mod.c:    Source module which contains functions which allow ksym.c
  410. +        to resolve symbols found in loadable kernel modules.    
  411. +
  412.  syslogd.c:    Source code for the system log daemon.
  413.  
  414.  syslog.c:    A slightly modified version of the syslog.c file found in
  415. @@ -46,3 +49,10 @@
  416.  
  417.  kernel.patch:    A source code patch which modifies the linux kernel to
  418.          delimit addresses for symbolic translation by klogd.
  419. +
  420. +oops.c:        C source for a loadable kernel module which can be used
  421. +        to generate a kernel protection fault.  This is used to
  422. +        test the address resolution capabilities of klogd.
  423. +
  424. +oops_test.c:    A small driver program used in conjunction with the oops
  425. +        module to generate a kernel protection fault.
  426. diff -u --new-file --recursive v1.3-1/sysklogd-1.3/Makefile sysklogd-1.3/Makefile
  427. --- v1.3-1/sysklogd-1.3/Makefile    Sun Mar 31 11:19:05 1996
  428. +++ sysklogd-1.3/Makefile    Thu May  2 15:19:07 1996
  429. @@ -52,15 +52,18 @@
  430.  .c.o:
  431.      ${CC} ${CFLAGS} -c $*.c
  432.  
  433. -all:    syslogd    klogd syslog_tst
  434. +all: syslogd klogd
  435. +
  436. +test: syslog_tst ksym oops_test
  437.  
  438.  install: install_man install_exec
  439.  
  440.  syslogd: syslogd.o pidfile.o
  441.      ${CC} ${LDFLAGS} -o syslogd syslogd.o pidfile.o ${LIBS}
  442.  
  443. -klogd:    klogd.o syslog.o pidfile.o ksym.o
  444. -    ${CC} ${LDFLAGS} -o klogd klogd.o syslog.o pidfile.o ksym.o ${LIBS}
  445. +klogd:    klogd.o syslog.o pidfile.o ksym.o ksym_mod.o
  446. +    ${CC} ${LDFLAGS} -o klogd klogd.o syslog.o pidfile.o ksym.o \
  447. +        ksym_mod.o ${LIBS}
  448.  
  449.  syslog_tst: syslog_tst.o
  450.      ${CC} ${LDFLAGS} -o syslog_tst syslog_tst.o
  451. @@ -77,14 +80,29 @@
  452.  ksym.o: ksym.c klogd.h
  453.      ${CC} ${CFLAGS} ${KLOGD_FLAGS} -c ksym.c
  454.  
  455. +ksym_mod.o: ksym_mod.c klogd.h
  456. +    ${CC} ${CFLAGS} ${KLOGD_FLAGS} -c ksym_mod.c
  457. +
  458.  syslog_tst.o: syslog_tst.c
  459.      ${CC} ${CFLAGS} -c syslog_tst.c
  460.  
  461. +oops_test: oops.o
  462. +    ${CC} ${CFLAGS} -o oops_test oops_test.c
  463. +
  464. +oops.o: oops.c
  465. +    ${CC} ${CFLAGS} -D__KERNEL__ -DMODULE -c oops.c
  466. +
  467. +ksym: ksym_test.o ksym_mod.o
  468. +    ${CC} ${LDFLAGS} -o ksym ksym_test.o ksym_mod.o
  469. +
  470. +ksym_test.o: ksym.c
  471. +    ${CC} ${CFLAGS} -DTEST -o ksym_test.o -c ksym.c
  472. +
  473.  clean:
  474.      rm -f *.o *.log *~ *.orig
  475.  
  476.  clobber: clean
  477. -    rm -f syslogd klogd syslog_tst TAGS
  478. +    rm -f syslogd klogd ksym syslog_tst oops_test TAGS
  479.  
  480.  install_exec: syslogd klogd
  481.      ${INSTALL} -m 500 -s syslogd ${BINDIR}/syslogd
  482. diff -u --new-file --recursive v1.3-1/sysklogd-1.3/klogd.c sysklogd-1.3/klogd.c
  483. --- v1.3-1/sysklogd-1.3/klogd.c    Sun Mar 31 11:19:05 1996
  484. +++ sysklogd-1.3/klogd.c    Wed Apr 17 13:42:58 1996
  485. @@ -380,7 +380,7 @@
  486.      {
  487.          fputs("Logging line:\n", stderr);
  488.          fprintf(stderr, "\tLine: %s\n", fmt);
  489. -        fprintf(stderr, "\tPriority: %c\n", *(fmt+1));
  490. +        fprintf(stderr, "\tPriority: %d\n", priority);
  491.      }
  492.  
  493.      /* Handle output to a file. */
  494. diff -u --new-file --recursive v1.3-1/sysklogd-1.3/klogd.h sysklogd-1.3/klogd.h
  495. --- v1.3-1/sysklogd-1.3/klogd.h    Sun Mar 31 11:19:05 1996
  496. +++ sysklogd-1.3/klogd.h    Sun Mar 31 14:24:42 1996
  497. @@ -13,5 +13,6 @@
  498.  
  499.  /* Function prototypes. */
  500.  extern int InitKsyms(char *);
  501. +extern int InitMsyms(void);
  502.  extern char * ExpandKadds(char *, char *);
  503.  extern void Syslog(int priority, char *fmt, ...);
  504. diff -u --new-file --recursive v1.3-1/sysklogd-1.3/ksym.c sysklogd-1.3/ksym.c
  505. --- v1.3-1/sysklogd-1.3/ksym.c    Sun Mar 31 11:19:05 1996
  506. +++ sysklogd-1.3/ksym.c    Wed May  1 16:24:54 1996
  507. @@ -1,6 +1,7 @@
  508.  /*
  509.      ksym.c - functions for kernel address->symbol translation
  510. -    Copyright (c) 1995  Dr. G.W. Wettstein <greg@wind.rmcc.com>
  511. +    Copyright (c) 1995, 1996  Dr. G.W. Wettstein <greg@wind.rmcc.com>
  512. +    Copyright (c) 1996 Enjellic Systems Development
  513.  
  514.      This file is part of the sysklogd package, a kernel and system log daemon.
  515.  
  516. @@ -69,27 +70,20 @@
  517.  #include <malloc.h>
  518.  #include <sys/utsname.h>
  519.  #include "klogd.h"
  520. +#include "ksyms.h"
  521.  
  522.  #define VERBOSE_DEBUGGING 0
  523.  
  524.  
  525. -/* Variables, structures and type definitions static to this module. */
  526. +/* Variables static to this module. */
  527.  struct sym_table
  528.  {
  529.      unsigned long value;
  530.      char *name;
  531.  };
  532.  
  533. -struct symbol
  534. -{
  535. -    char *name;
  536. -    int size;
  537. -    int offset;
  538. -};
  539. -
  540. -static struct sym_table *sym_array = (struct sym_table *) 0;
  541. -
  542.  static int num_syms = 0;
  543. +static struct sym_table *sym_array = (struct sym_table *) 0;
  544.  
  545.  static char *system_maps[] =
  546.  {
  547. @@ -104,7 +98,7 @@
  548.  
  549.  
  550.  #if defined(TEST)
  551. -static int debugging = 1;
  552. +int debugging;
  553.  #else
  554.  extern int debugging;
  555.  #endif
  556. @@ -192,7 +186,7 @@
  557.       */
  558.      while ( !feof(sym_file) )
  559.      {
  560. -        if ( fscanf(sym_file, "%8lx %c %s\n", &address, &type, sym)
  561. +        if ( fscanf(sym_file, "%lx %c %s\n", &address, &type, sym)
  562.              != 3 )
  563.          {
  564.              Syslog(LOG_ERR, "Error in symbol table input.");
  565. @@ -303,7 +297,7 @@
  566.          version = 0;
  567.          while ( !feof(sym_file) && (version == 0) )
  568.          {
  569. -            if ( fscanf(sym_file, "%8lx %c %s\n", &address, \
  570. +            if ( fscanf(sym_file, "%lx %c %s\n", &address, \
  571.                      &type, sym) != 3 )
  572.              {
  573.                  Syslog(LOG_ERR, "Error in symbol table input.");
  574. @@ -527,7 +521,7 @@
  575.   *        closely matching the address is returned.
  576.   **************************************************************************/
  577.  
  578. -extern char * LookupSymbol(value, sym)
  579. +static char * LookupSymbol(value, sym)
  580.  
  581.      unsigned long value;
  582.  
  583. @@ -556,6 +550,9 @@
  584.          last = sym_array[lp].name;
  585.      }
  586.  
  587. +    if ( (last = LookupModuleSymbol(value, sym)) != (char *) 0 )
  588. +        return(last);
  589. +
  590.      return((char *) 0);
  591.  }
  592.  
  593. @@ -594,8 +591,29 @@
  594.      auto int value;
  595.  
  596.      auto struct symbol sym;
  597. +
  598. +
  599. +    /*
  600. +     * This is as handy a place to put this as anyplace.
  601. +     *
  602. +     * Since the insertion of kernel modules can occur in a somewhat
  603. +     * dynamic fashion we need some mechanism to insure that the
  604. +     * kernel symbol tables get read just prior to when they are
  605. +     * needed.
  606. +     *
  607. +     * To accomplish this we look for the Oops string and use its
  608. +     * presence as a signal to load the module symbols.
  609. +     *
  610. +     * This is not the best solution of course, especially if the
  611. +     * kernel is rapidly going out to lunch.  What really needs to
  612. +     * be done is to somehow generate a callback from the
  613. +     * kernel whenever a module is loaded or unloaded.  I am
  614. +     * open for patches.
  615. +     */
  616. +    if ( (strstr(line, "Oops:") != (char *) 0) && !InitMsyms() )
  617. +        Syslog(LOG_WARNING, "Cannot load kernel module symbols.\n");
  618.      
  619. -    
  620. +
  621.      /*
  622.       * Early return if there do not appear to be any kernel
  623.       * messages in this line.
  624. @@ -670,21 +688,17 @@
  625.  
  626.  extern int main(int argc, char *argv[])
  627.  {
  628. -    auto long int value;
  629.      auto char line[1024], eline[2048];
  630. +
  631. +    debugging = 1;
  632.      
  633.      
  634. -#if 0
  635. -    value = atol(argv[1]);
  636. -    fprintf(stdout, "Value of %ld: %s\n", value, LookupSymbol(value));
  637. -#endif
  638. -
  639.      if ( !InitKsyms((char *) 0) )
  640.      {
  641.          fputs("ksym: Error loading system map.\n", stderr);
  642.          return(1);
  643.      }
  644. -    
  645. +
  646.      while ( !feof(stdin) )
  647.      {
  648.          gets(line);
  649. diff -u --new-file --recursive v1.3-1/sysklogd-1.3/ksym_mod.c sysklogd-1.3/ksym_mod.c
  650. --- v1.3-1/sysklogd-1.3/ksym_mod.c    Wed Dec 31 18:00:00 1969
  651. +++ sysklogd-1.3/ksym_mod.c    Wed May  1 16:15:25 1996
  652. @@ -0,0 +1,587 @@
  653. +/*
  654. +    ksym_mod.c - functions for building symbol lookup tables for klogd
  655. +    Copyright (c) 1995, 1996  Dr. G.W. Wettstein <greg@wind.rmcc.com>
  656. +    Copyright (c) 1996 Enjellic Systems Development
  657. +
  658. +    This file is part of the sysklogd package, a kernel and system log daemon.
  659. +
  660. +    This program is free software; you can redistribute it and/or modify
  661. +    it under the terms of the GNU General Public License as published by
  662. +    the Free Software Foundation; either version 2 of the License, or
  663. +    (at your option) any later version.
  664. +
  665. +    This program is distributed in the hope that it will be useful,
  666. +    but WITHOUT ANY WARRANTY; without even the implied warranty of
  667. +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  668. +    GNU General Public License for more details.
  669. +
  670. +    You should have received a copy of the GNU General Public License
  671. +    along with this program; if not, write to the Free Software
  672. +    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  673. +*/
  674. +
  675. +/*
  676. + * This file implements functions which are useful for building
  677. + * a symbol lookup table based on the in kernel symbol table
  678. + * maintained by the Linux kernel.
  679. + *
  680. + * Proper logging of kernel panics generated by loadable modules
  681. + * tends to be difficult.  Since the modules are loaded dynamically
  682. + * their addresses are not known at kernel load time.  A general
  683. + * protection fault (Oops) cannot be properly deciphered with 
  684. + * classic methods using the static symbol map produced at link time.
  685. + *
  686. + * One solution to this problem is to have klogd attempt to translate
  687. + * addresses from module when the fault occurs.  By referencing the
  688. + * the kernel symbol table proper resolution of these symbols is made
  689. + * possible.
  690. + *
  691. + * At least that is the plan.
  692. + */
  693. +
  694. +
  695. +/* Includes. */
  696. +#include <stdlib.h>
  697. +#include <malloc.h>
  698. +#include <unistd.h>
  699. +#include <signal.h>
  700. +#include <errno.h>
  701. +#include <sys/fcntl.h>
  702. +#include <sys/stat.h>
  703. +#include <linux/time.h>
  704. +#include <linux/module.h>
  705. +#include <stdarg.h>
  706. +#include <paths.h>
  707. +
  708. +#include "klogd.h"
  709. +#include "ksyms.h"
  710. +
  711. +
  712. +/*
  713. + * The following bit uses some kernel/library magic to product what
  714. + * looks like a function call to user level code.  This function is
  715. + * actually a system call in disguise.  The purpose of the getsyms
  716. + * call is to return a current copy of the in-kernel symbol table.
  717. + */
  718. +#define __LIBRARY__
  719. +#include <linux/unistd.h>
  720. +# define __NR_getsyms __NR_get_kernel_syms
  721. +_syscall1(int, getsyms, struct kernel_sym *, syms);
  722. +#undef __LIBRARY__
  723. +extern int getsyms(struct kernel_sym *);
  724. +
  725. +
  726. +/* Variables static to this module. */
  727. +struct sym_table
  728. +{
  729. +    unsigned long value;
  730. +    char *name;
  731. +};
  732. +
  733. +struct Module
  734. +{
  735. +    struct sym_table *sym_array;
  736. +    int num_syms;
  737. +
  738. +    char *name;
  739. +    struct module module;
  740. +};
  741. +
  742. +static int num_modules;
  743. +struct Module *sym_array_modules = (struct Module *) 0;
  744. +
  745. +static int have_modules = 0;
  746. +
  747. +#if defined(TEST)
  748. +static int debugging = 1;
  749. +#else
  750. +extern int debugging;
  751. +#endif
  752. +
  753. +
  754. +/* Function prototypes. */
  755. +static void FreeModules(void);
  756. +static int AddSymbol(struct Module *mp, unsigned long, char *);
  757. +static int AddModule(unsigned long, char *);
  758. +static int symsort(const void *, const void *);
  759. +
  760. +
  761. +/**************************************************************************
  762. + * Function:    InitMsyms
  763. + *
  764. + * Purpose:    This function is responsible for building a symbol
  765. + *        table which can be used to resolve addresses for
  766. + *        loadable modules.
  767. + *
  768. + * Arguements:    Void
  769. + *
  770. + * Return:    A boolean return value is assumed.
  771. + *
  772. + *        A false value indicates that something went wrong.
  773. + *
  774. + *        True if loading is successful.
  775. + **************************************************************************/
  776. +
  777. +extern int InitMsyms()
  778. +
  779. +{
  780. +    auto int    rtn,
  781. +            tmp;
  782. +
  783. +    auto struct kernel_sym    *ksym_table,
  784. +                *p;
  785. +
  786. +
  787. +    /* Init the symbol table if one exists. */
  788. +    if ( num_modules > 0 )
  789. +        FreeModules();
  790. +
  791. +
  792. +    /*
  793. +     * The system call which returns the kernel symbol table has
  794. +     * essentialy two modes of operation.  Called with a null pointer
  795. +     * the system call returns the number of symbols defined in the
  796. +     * the table.
  797. +     *
  798. +     * The second mode of operation is to pass a valid pointer to
  799. +     * the call which will then load the current symbol table into
  800. +     * the memory provided.
  801. +     *
  802. +     * Returning the symbol table is essentially an all or nothing
  803. +     * proposition so we need to pre-allocate enough memory for the
  804. +     * complete table regardless of how many symbols we need.
  805. +     *
  806. +     * Bummer.
  807. +     */
  808. +    rtn = getsyms((struct kernel_sym *) 0);
  809. +    if ( debugging )
  810. +        fprintf(stderr, "Loading kernel module symbols - "
  811. +            "Size of table: %d\n", rtn);
  812. +
  813. +    ksym_table = (struct kernel_sym *) malloc(rtn * \
  814. +                          sizeof(struct kernel_sym));
  815. +    if ( ksym_table == (struct kernel_sym *) 0 )
  816. +    {
  817. +        Syslog(LOG_WARNING, " Failed memory allocation for kernel "
  818. +               "symbol table.\n");
  819. +        return(0);
  820. +    }
  821. +    if ( (rtn = getsyms(ksym_table)) == 0 )
  822. +        Syslog(LOG_WARNING, "Kernel symbol read returned 0\n");
  823. +
  824. +
  825. +    /*
  826. +     * Build a symbol table compatible with the other one used by
  827. +     * klogd.
  828. +     */
  829. +    tmp = rtn;
  830. +    p = ksym_table;
  831. +    while ( tmp-- )
  832. +    {
  833. +         if ( !AddModule(p->value, p->name) )
  834. +        {
  835. +            Syslog(LOG_WARNING, "Error adding kernel module table "
  836. +                "entry.\n");
  837. +            free(ksym_table);
  838. +            return(0);
  839. +        }
  840. +        ++p;
  841. +    }
  842. +
  843. +    /* Sort the symbol tables in each module. */
  844. +    for (tmp= 0; tmp < num_modules; ++tmp)
  845. +    {
  846. +        if ( sym_array_modules[tmp].num_syms < 2 )
  847. +            continue;
  848. +        qsort(sym_array_modules[tmp].sym_array, \
  849. +              sym_array_modules[tmp].num_syms, \
  850. +              sizeof(struct sym_table), symsort);
  851. +    }
  852. +
  853. +    free(ksym_table);
  854. +    return(1);
  855. +}
  856. +
  857. +
  858. +static int symsort(p1, p2)
  859. +
  860. +     const void *p1;
  861. +
  862. +     const void *p2;
  863. +
  864. +{
  865. +    auto const struct sym_table    *sym1 = p1,
  866. +                    *sym2 = p2;
  867. +
  868. +    if ( sym1->value < sym2->value )
  869. +        return(-1);
  870. +    if ( sym1->value == sym2->value )
  871. +        return(0);
  872. +    return(1);
  873. +}
  874. +
  875. +
  876. +/**************************************************************************
  877. + * Function:    FreeModules
  878. + *
  879. + * Purpose:    This function is used to free all memory which has been
  880. + *        allocated for the modules and their symbols.
  881. + *
  882. + * Arguements:    None specified.
  883. + *
  884. + * Return:    void
  885. + **************************************************************************/
  886. +
  887. +static void FreeModules()
  888. +
  889. +{
  890. +    auto int    nmods,
  891. +            nsyms;
  892. +
  893. +    auto struct Module *mp;
  894. +
  895. +
  896. +    for (nmods= 0; nmods <num_modules; ++nmods)
  897. +    {
  898. +        mp = &sym_array_modules[nmods];
  899. +        if ( mp->num_syms == 0 )
  900. +            continue;
  901. +           
  902. +        for (nsyms= 0; nsyms < mp->num_syms; ++nsyms)
  903. +            free(mp->sym_array[nsyms].name);
  904. +        free(mp->sym_array);
  905. +    }
  906. +
  907. +    free(sym_array_modules);
  908. +    sym_array_modules = (struct Module *) 0;
  909. +    have_modules = num_modules = 0;
  910. +    return;
  911. +}
  912. +
  913. +
  914. +/**************************************************************************
  915. + * Function:    AddModule
  916. + *
  917. + * Purpose:    This function is responsible for adding a module to
  918. + *        the list of currently loaded modules.
  919. + *
  920. + * Arguements:    (unsigned long) address, (char *) symbol
  921. + *
  922. + *        address:->    The address of the module.
  923. + *
  924. + *        symbol:->    The name of the module.
  925. + *
  926. + * Return:    int
  927. + **************************************************************************/
  928. +
  929. +static int AddModule(address, symbol)
  930. +
  931. +     unsigned long address;
  932. +
  933. +     char *symbol;
  934. +
  935. +{
  936. +    auto int memfd;
  937. +
  938. +    auto struct Module *mp;
  939. +
  940. +
  941. +    /* Return if we have loaded the modules. */
  942. +    if ( have_modules )
  943. +        return(1);
  944. +
  945. +    /*
  946. +     * The following section of code is responsible for determining
  947. +     * whether or not we are done reading the list of modules.
  948. +     */
  949. +    if ( symbol[0] == '#' )
  950. +    {
  951. +        if ( symbol[1] == '\0' )
  952. +        {
  953. +            /*
  954. +             * A symbol which consists of a # sign only
  955. +             * signifies a a resident kernel segment.  When we
  956. +             * hit one of these we are done reading the
  957. +             * module list.
  958. +             */
  959. +            have_modules = 1;
  960. +            return(1);
  961. +        }
  962. +
  963. +        /* Allocate space for the module. */
  964. +        sym_array_modules = (struct Module *) \
  965. +            realloc(sym_array_modules, \
  966. +                (num_modules+1) * sizeof(struct Module));
  967. +        if ( sym_array_modules == (struct Module *) 0 )
  968. +        {
  969. +            Syslog(LOG_WARNING, "Cannot allocate Module array.\n");
  970. +            return(0);
  971. +        }
  972. +        mp = &sym_array_modules[num_modules];
  973. +
  974. +        if ( (memfd = open("/dev/kmem", O_RDONLY)) < 0 )
  975. +        {
  976. +            Syslog(LOG_WARNING, "Error opening /dev/kmem\n");
  977. +            return(1);
  978. +        }
  979. +        if ( lseek(memfd, address, SEEK_SET) < 0 )
  980. +        {
  981. +            Syslog(LOG_WARNING, "Error seeking in /dev/kmem\n");
  982. +            return(0);
  983. +        }
  984. +        if ( read(memfd, \
  985. +              (char *)&sym_array_modules[num_modules].module,  \
  986. +              sizeof(struct module)) < 0 )
  987. +        {
  988. +            Syslog(LOG_WARNING, "Error reading module "
  989. +                   "descriptor.\n");
  990. +            return(0);
  991. +        }
  992. +        close(memfd);
  993. +
  994. +        /* Save the module name. */
  995. +        mp->name = (char *) malloc(strlen(&symbol[1]) + 1);
  996. +        if ( mp->name == (char *) 0 )
  997. +            return(0);
  998. +        strcpy(mp->name, &symbol[1]);
  999. +
  1000. +        mp->num_syms = 0;
  1001. +        mp->sym_array = (struct sym_table *) 0;
  1002. +        ++num_modules;
  1003. +        return(1);
  1004. +    }
  1005. +    else
  1006. +    {
  1007. +        mp = &sym_array_modules[num_modules - 1];
  1008. +        AddSymbol(mp, address, symbol);
  1009. +    }
  1010. +
  1011. +
  1012. +    return(1);
  1013. +}
  1014. +
  1015. +
  1016. +/**************************************************************************
  1017. + * Function:    AddSymbol
  1018. + *
  1019. + * Purpose:    This function is responsible for adding a symbol name
  1020. + *        and its address to the symbol table.
  1021. + *
  1022. + * Arguements:    (struct Module *) mp, (unsigned long) address, (char *) symbol
  1023. + *
  1024. + *        mp:->    A pointer to the module which the symbol is
  1025. + *            to be added to.
  1026. + *
  1027. + *        address:->    The address of the symbol.
  1028. + *
  1029. + *        symbol:->    The name of the symbol.
  1030. + *
  1031. + * Return:    int
  1032. + *
  1033. + *        A boolean value is assumed.  True if the addition is
  1034. + *        successful.  False if not.
  1035. + **************************************************************************/
  1036. +
  1037. +static int AddSymbol(mp, address, symbol)
  1038. +
  1039. +    struct Module *mp;     
  1040. +
  1041. +    unsigned long address;
  1042. +    
  1043. +    char *symbol;
  1044. +    
  1045. +{
  1046. +    auto int tmp;
  1047. +
  1048. +
  1049. +    /* Allocate space for the symbol table entry. */
  1050. +    mp->sym_array = (struct sym_table *) realloc(mp->sym_array, \
  1051. +            (mp->num_syms+1) * sizeof(struct sym_table));
  1052. +    if ( mp->sym_array == (struct sym_table *) 0 )
  1053. +        return(0);
  1054. +
  1055. +    /* Then the space for the symbol. */
  1056. +    tmp = strlen(symbol);
  1057. +    tmp += (strlen(mp->name) + 1);
  1058. +    mp->sym_array[mp->num_syms].name = (char *) malloc(tmp + 1);
  1059. +    if ( mp->sym_array[mp->num_syms].name == (char *) 0 )
  1060. +        return(0);
  1061. +    memset(mp->sym_array[mp->num_syms].name, '\0', tmp + 1);
  1062. +    
  1063. +    /* Stuff interesting information into the module. */
  1064. +    mp->sym_array[mp->num_syms].value = address;
  1065. +    strcpy(mp->sym_array[mp->num_syms].name, mp->name);
  1066. +    strcat(mp->sym_array[mp->num_syms].name, ":");
  1067. +    strcat(mp->sym_array[mp->num_syms].name, symbol);
  1068. +    ++mp->num_syms;
  1069. +
  1070. +    return(1);
  1071. +}
  1072. +
  1073. +
  1074. +/**************************************************************************
  1075. + * Function:    LookupModuleSymbol
  1076. + *
  1077. + * Purpose:    Find the symbol which is related to the given address from
  1078. + *        a kernel module.
  1079. + *
  1080. + * Arguements:    (long int) value, (struct symbol *) sym
  1081. + *
  1082. + *        value:->    The address to be located.
  1083. + * 
  1084. + *        sym:->        A pointer to a structure which will be
  1085. + *                loaded with the symbol's parameters.
  1086. + *
  1087. + * Return:    (char *)
  1088. + *
  1089. + *        If a match cannot be found a diagnostic string is printed.
  1090. + *        If a match is found the pointer to the symbolic name most
  1091. + *        closely matching the address is returned.
  1092. + **************************************************************************/
  1093. +
  1094. +extern char * LookupModuleSymbol(value, sym)
  1095. +
  1096. +    unsigned long value;
  1097. +
  1098. +    struct symbol *sym;
  1099. +    
  1100. +{
  1101. +    auto int    nmod,
  1102. +            nsym;
  1103. +
  1104. +    auto struct sym_table *last;
  1105. +
  1106. +    auto struct Module *mp;
  1107. +
  1108. +
  1109. +    sym->size = 0;
  1110. +    sym->offset = 0;
  1111. +    if ( num_modules == 0 )
  1112. +        return((char *) 0);
  1113. +    
  1114. +    for(nmod= 0; nmod < num_modules; ++nmod)
  1115. +    {
  1116. +        mp = &sym_array_modules[nmod];
  1117. +
  1118. +        /*
  1119. +         * Run through the list of symbols in this module and
  1120. +         * see if the address can be resolved.
  1121. +         */
  1122. +        for(nsym= 1, last = &mp->sym_array[0];
  1123. +            nsym < mp->num_syms;
  1124. +            ++nsym)
  1125. +        {
  1126. +            if ( mp->sym_array[nsym].value > value )
  1127. +            {        
  1128. +                sym->offset = value - last->value;
  1129. +                sym->size = mp->sym_array[nsym].value - \
  1130. +                    last->value;
  1131. +                return(last->name);
  1132. +            }
  1133. +            last = &mp->sym_array[nsym];
  1134. +        }
  1135. +
  1136. +
  1137. +        /*
  1138. +         * At this stage of the game we still cannot give up the
  1139. +         * ghost.  There is the possibility that the address is
  1140. +         * from a module which has no symbols registered with
  1141. +         * the kernel.  The solution is to compare the address
  1142. +         * against the starting address and extant of the module
  1143. +         * If it is in this range we can at least return the
  1144. +         * name of the module.
  1145. +         */
  1146. +        if ( (void *) value >= mp->module.addr &&
  1147. +             (void *) value <= (mp->module.addr + \
  1148. +                    mp->module.size * 4096) )
  1149. +        {
  1150. +            /*
  1151. +             * A special case needs to be checked for.  The above
  1152. +             * conditional tells us that we are within the
  1153. +             * extant of this module but symbol lookup has
  1154. +             * failed.
  1155. +             *
  1156. +             * We need to check to see if any symbols have
  1157. +             * been defined in this module.  If there have been
  1158. +             * symbols defined the assumption must be made that
  1159. +             * the faulting address lies somewhere beyond the
  1160. +             * last symbol.  About the only thing we can do
  1161. +             * at this point is use an offset from this
  1162. +             * symbol.
  1163. +             */
  1164. +            if ( mp->num_syms > 0 )
  1165. +            {
  1166. +                last = &mp->sym_array[mp->num_syms - 1];
  1167. +                sym->size = (int) mp->module.addr + \
  1168. +                    (mp->module.size * 4096) - value;
  1169. +                sym->offset = value - last->value;
  1170. +                return(last->name);
  1171. +            }
  1172. +
  1173. +            /*
  1174. +             * There were no symbols defined for this module.
  1175. +             * Return the module name and the offset of the
  1176. +             * faulting address in the module.
  1177. +             */
  1178. +            sym->size = mp->module.size * 4096;
  1179. +            sym->offset = (void *) value - mp->module.addr;
  1180. +            return(mp->name);
  1181. +        }
  1182. +    }
  1183. +
  1184. +    /* It has been a hopeless exercise. */
  1185. +    return((char *) 0);
  1186. +}
  1187. +
  1188. +
  1189. +/*
  1190. + * Setting the -DTEST define enables the following code fragment to
  1191. + * be compiled.  This produces a small standalone program which will
  1192. + * dump the current kernel symbol table.
  1193. + */
  1194. +#if defined(TEST)
  1195. +
  1196. +#include <stdarg.h>
  1197. +
  1198. +
  1199. +extern int main(int, char **);
  1200. +
  1201. +
  1202. +int main(argc, argv)
  1203. +
  1204. +    int argc;
  1205. +
  1206. +    char *argv[];
  1207. +
  1208. +{
  1209. +    auto int lp, syms;
  1210. +
  1211. +
  1212. +    if ( !InitMsyms() )
  1213. +    {
  1214. +        fprintf(stderr, "Cannot load module symbols.\n");
  1215. +        return(1);
  1216. +    }
  1217. +
  1218. +    printf("Number of modules: %d\n\n", num_modules);
  1219. +
  1220. +    for(lp= 0; lp < num_modules; ++lp)
  1221. +    {
  1222. +        printf("Module #%d = %s, Number of symbols = %d\n", lp + 1, \
  1223. +               sym_array_modules[lp].name, \
  1224. +               sym_array_modules[lp].num_syms);
  1225. +
  1226. +        for (syms= 0; syms < sym_array_modules[lp].num_syms; ++syms)
  1227. +        {
  1228. +            printf("\tSymbol #%d\n", syms + 1);
  1229. +            printf("\tName: %s\n", \
  1230. +                   sym_array_modules[lp].sym_array[syms].name);
  1231. +            printf("\tAddress: %lx\n\n", \
  1232. +                   sym_array_modules[lp].sym_array[syms].value);
  1233. +        }
  1234. +    }
  1235. +
  1236. +    FreeModules();
  1237. +    return(0);
  1238. +}
  1239. +#endif
  1240. diff -u --new-file --recursive v1.3-1/sysklogd-1.3/ksyms.h sysklogd-1.3/ksyms.h
  1241. --- v1.3-1/sysklogd-1.3/ksyms.h    Wed Dec 31 18:00:00 1969
  1242. +++ sysklogd-1.3/ksyms.h    Sun Mar 31 16:44:26 1996
  1243. @@ -0,0 +1,36 @@
  1244. +/*
  1245. +    ksym.h - Definitions for symbol table utilities.
  1246. +    Copyright (c) 1995, 1996  Dr. G.W. Wettstein <greg@wind.rmcc.com>
  1247. +    Copyright (c) 1996 Enjellic Systems Development
  1248. +
  1249. +    This file is part of the sysklogd package, a kernel and system log daemon.
  1250. +
  1251. +    This program is free software; you can redistribute it and/or modify
  1252. +    it under the terms of the GNU General Public License as published by
  1253. +    the Free Software Foundation; either version 2 of the License, or
  1254. +    (at your option) any later version.
  1255. +
  1256. +    This program is distributed in the hope that it will be useful,
  1257. +    but WITHOUT ANY WARRANTY; without even the implied warranty of
  1258. +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1259. +    GNU General Public License for more details.
  1260. +
  1261. +    You should have received a copy of the GNU General Public License
  1262. +    along with this program; if not, write to the Free Software
  1263. +    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1264. +*/
  1265. +
  1266. +
  1267. +
  1268. +/* Variables, structures and type definitions static to this module. */
  1269. +
  1270. +struct symbol
  1271. +{
  1272. +    char *name;
  1273. +    int size;
  1274. +    int offset;
  1275. +};
  1276. +
  1277. +
  1278. +/* Function prototypes. */
  1279. +extern char * LookupModuleSymbol(unsigned long int, struct symbol *);
  1280. diff -u --new-file --recursive v1.3-1/sysklogd-1.3/oops.c sysklogd-1.3/oops.c
  1281. --- v1.3-1/sysklogd-1.3/oops.c    Wed Dec 31 18:00:00 1969
  1282. +++ sysklogd-1.3/oops.c    Thu May  2 15:25:49 1996
  1283. @@ -0,0 +1,118 @@
  1284. +/*
  1285. + * Loadable driver which provides the ability to generate a kernel
  1286. + * protection fault.  Mainly useful for testing the address translation
  1287. + * capabilities of klogd.
  1288. + *
  1289. + * Fri Oct 27 14:34:27 CDT 1995:  Dr. Wettstein
  1290. + *
  1291. + *    Initial version.
  1292. + */
  1293. +
  1294. +#define NEW_MODULES
  1295. +
  1296. +/* Kernel includes. */
  1297. +#include <linux/kernel.h>
  1298. +#include <linux/config.h>
  1299. +#include <linux/errno.h>
  1300. +#include <linux/fs.h>
  1301. +
  1302. +/* Standard module stuff. */
  1303. +#if defined(NEW_MODULES)
  1304. +#include <linux/module.h>
  1305. +#else
  1306. +#include <linux/module.h>
  1307. +#include <linux/version.h>
  1308. +char kernel_version[] = UTS_RELEASE;
  1309. +#endif
  1310. +
  1311. +
  1312. +static int major = 32;
  1313. +
  1314. +
  1315. +#ifdef MODULE
  1316. +static int oops_ioctl(struct inode *, struct file *, unsigned int cmd, unsigned long arg);
  1317. +static int oops_open(struct inode * node, struct file * file);
  1318. +static void oops(void);
  1319. +
  1320. +static struct symbol_table these_symbols = {
  1321. +#include <linux/symtab_begin.h>
  1322. +    X(oops_open),
  1323. +    X(oops_ioctl),
  1324. +    X(oops),
  1325. +#include <linux/symtab_end.h>
  1326. +};
  1327. +
  1328. +/* driver specific module definitions */
  1329. +static struct file_operations oops_fops1 = {
  1330. +    NULL,        /* hw_lseek */
  1331. +    NULL,        /* hw_read */
  1332. +    NULL,        /* write */
  1333. +    NULL,        /* hw_readdir */
  1334. +    NULL,        /* hw_select */
  1335. +    oops_ioctl,    /* hw_ioctl */
  1336. +    NULL,        /* mmap */
  1337. +    oops_open,    /* hw_open */
  1338. +    NULL,        /* hw_release */
  1339. +    NULL        /* fsync */
  1340. +};
  1341. +
  1342. +static int oops_open(struct inode * node, struct file * file)
  1343. +{
  1344. +    printk("Called oops_open.\n");
  1345. +    return(0);
  1346. +}
  1347. +
  1348. +
  1349. +static int oops_ioctl(struct inode * node, struct file * file, \
  1350. +              unsigned int cmd, unsigned long arg)
  1351. +{
  1352. +    
  1353. +    printk("Called oops_ioctl.\n");
  1354. +    printk("Cmd: %d, Arg: %ld\n", cmd, arg);
  1355. +    if ( cmd == 1 )
  1356. +    {
  1357. +        oops();
  1358. +    }
  1359. +        
  1360. +    return(0);
  1361. +}
  1362. +
  1363. +static void oops()
  1364. +
  1365. +{
  1366. +    auto unsigned long *p = (unsigned long *) 828282828;
  1367. +    *p = 5;
  1368. +    return;
  1369. +}
  1370. +
  1371. +    
  1372. +int
  1373. +init_module(void)
  1374. +{
  1375. +    printk("oops: Module initilization.\n");
  1376. +    if (register_chrdev(major, "oops", &oops_fops1)) {
  1377. +        printk("register_chrdev failed.");
  1378. +        return -EIO;
  1379. +    }
  1380. +
  1381. +    printk("oops: Registering symbols.\n");
  1382. +      register_symtab(&these_symbols);
  1383. +    
  1384. +    return 0;
  1385. +}
  1386. +
  1387. +
  1388. +void
  1389. +cleanup_module(void)
  1390. +{
  1391. +    /* driver specific cleanups, ususally "unregister_*()" */
  1392. +    printk("oops: Module unloadeding.\n");
  1393. +    if (unregister_chrdev(major, "oops") != 0)
  1394. +        printk("cleanup_module failed\n");
  1395. +    else
  1396. +        printk("cleanup_module succeeded\n");
  1397. +
  1398. +    return;
  1399. +
  1400. +}
  1401. +#endif /* MODULE */
  1402. diff -u --new-file --recursive v1.3-1/sysklogd-1.3/oops_test.c sysklogd-1.3/oops_test.c
  1403. --- v1.3-1/sysklogd-1.3/oops_test.c    Wed Dec 31 18:00:00 1969
  1404. +++ sysklogd-1.3/oops_test.c    Fri Apr 26 13:07:32 1996
  1405. @@ -0,0 +1,52 @@
  1406. +/*
  1407. + * This is a small test program for generating a kernel protection fault
  1408. + * using the oops loadable module.
  1409. + *
  1410. + * Fri Apr 26 12:52:43 CDT 1996:  Dr. Wettstein
  1411. + *    Initial version.
  1412. + */
  1413. +
  1414. +
  1415. +/* Includes. */
  1416. +#include <stdio.h>
  1417. +#include <unistd.h>
  1418. +#include <fcntl.h>
  1419. +#include <sys/ioctl.h>
  1420. +
  1421. +
  1422. +/* Function prototypes. */
  1423. +extern int main(int, char **);
  1424. +
  1425. +
  1426. +extern int main(argc, argv)
  1427. +
  1428. +     int argc;
  1429. +
  1430. +     char *argv[];
  1431. +
  1432. +{
  1433. +    auto int fd;
  1434. +
  1435. +    if ( argc != 2 )
  1436. +    {
  1437. +        fprintf(stderr, "No oops device specified.\n");
  1438. +        return(1);
  1439. +    }
  1440. +
  1441. +    if ( (fd = open(argv[1], O_RDONLY)) < 0 )
  1442. +    {
  1443. +        fprintf(stderr, "Cannot open device: %s.\n", argv[1]);
  1444. +        return(1);
  1445. +    }
  1446. +
  1447. +    if ( ioctl(fd, 1, 0) < 0 )
  1448. +    {
  1449. +        fprintf(stderr, "Failed on oops.\n");
  1450. +        return(1);
  1451. +    }
  1452. +
  1453. +    printf("OOoops\n");
  1454. +
  1455. +    close(fd);
  1456. +    return(0);
  1457. +}
  1458. diff -u --new-file --recursive v1.3-1/sysklogd-1.3/syslogd.c sysklogd-1.3/syslogd.c
  1459. --- v1.3-1/sysklogd-1.3/syslogd.c    Sun Mar 31 11:19:05 1996
  1460. +++ sysklogd-1.3/syslogd.c    Thu May  2 15:18:09 1996
  1461. @@ -269,6 +269,14 @@
  1462.   *    when syslogd starts up.
  1463.   *
  1464.   *    Minor code cleanups.
  1465. + *
  1466. + * Thu May  2 15:15:33 CDT 1996:  Dr. Wettstein
  1467. + *    Fixed bug in init function which resulted in file descripters
  1468. + *    being orphaned when syslogd process was re-initialized with SIGHUP
  1469. + *    signal.  Thanks to Edvard Tuinder
  1470. + *    (Edvard.Tuinder@praseodymium.cistron.nl) for putting me on the
  1471. + *    trail of this bug.  I am amazed that we didn't catch this one
  1472. + *    before now.
  1473.   */
  1474.  
  1475.  
  1476. @@ -1846,47 +1854,37 @@
  1477.      register char *p;
  1478.      char cline[BUFSIZ];
  1479.  
  1480. -    dprintf("Called init.\n");
  1481.  
  1482.      /*
  1483. -     *  Close all open log files.
  1484. +     *  Close all open log files and free log descriptor array.
  1485.       */
  1486. +    dprintf("Called init.\n");
  1487.      Initialized = 0;
  1488.      if ( nlogs > -1 )
  1489.      {
  1490.          dprintf("Initializing log structures.\n");
  1491. +
  1492. +        for (lognum = 0; lognum <= nlogs; lognum++ ) {
  1493. +            f = &Files[lognum];
  1494. +
  1495. +            /* flush any pending output */
  1496. +            if (f->f_prevcount)
  1497. +                fprintlog(f, LocalHostName, 0, (char *)NULL);
  1498. +
  1499. +            switch (f->f_type) {
  1500. +                case F_FILE:
  1501. +                case F_TTY:
  1502. +                case F_CONSOLE:
  1503. +                    (void) close(f->f_file);
  1504. +                break;
  1505. +            }
  1506. +        }
  1507. +
  1508.          nlogs = -1;
  1509.          free((void *) Files);
  1510.          Files = (struct filed *) 0;
  1511.      }
  1512.      
  1513. -#ifdef SYSV
  1514. -    for (lognum = 0; lognum <= nlogs; lognum++ ) {
  1515. -        f = &Files[lognum];
  1516. -#else
  1517. -    for (f = Files; f != NULL; f = next) {
  1518. -#endif
  1519. -        /* flush any pending output */
  1520. -        if (f->f_prevcount)
  1521. -            fprintlog(f, LocalHostName, 0, (char *)NULL);
  1522. -
  1523. -        switch (f->f_type) {
  1524. -          case F_FILE:
  1525. -          case F_TTY:
  1526. -          case F_CONSOLE:
  1527. -            (void) close(f->f_file);
  1528. -            break;
  1529. -        }
  1530. -#ifdef SYSV
  1531. -        f->f_type = F_UNUSED;    /* clear entry - ASP */
  1532. -    }
  1533. -#else
  1534. -        next = f->f_next;
  1535. -        free((char *) f);
  1536. -    }
  1537. -    Files = NULL;
  1538. -    nextp = &OBFiles;
  1539. -#endif
  1540.  
  1541.      /* open the configuration file */
  1542.      if ((cf = fopen(ConfFile, "r")) == NULL) {
  1543. diff -u --new-file --recursive v1.3-1/sysklogd-1.3/version.h sysklogd-1.3/version.h
  1544. --- v1.3-1/sysklogd-1.3/version.h    Sun Mar 31 11:19:05 1996
  1545. +++ sysklogd-1.3/version.h    Wed Apr 17 15:15:58 1996
  1546. @@ -1,2 +1,2 @@
  1547.  #define VERSION "1.3"
  1548. -#define PATCHLEVEL "1"
  1549. +#define PATCHLEVEL "2"
  1550. Cut here to complete separating patch 2. ----------------------------------
  1551.  
  1552. Cut here to begin separating patch 3. -------------------------------------
  1553. diff -u --new-file --recursive v1.3-2/sysklogd-1.3/ANNOUNCE ./sysklogd-1.3/ANNOUNCE
  1554. --- v1.3-2/sysklogd-1.3/ANNOUNCE    Tue Feb 27 16:19:26 1996
  1555. +++ ./sysklogd-1.3/ANNOUNCE    Thu Aug 29 08:44:55 1996
  1556. @@ -1,6 +1,6 @@
  1557. -On behalf of Martin Schulze, the beta-testers and other members of the
  1558. -Linux INTERNET community who have helped shape and debug this package
  1559. -I am pleased to announce version 1.3 of the sysklogd package.
  1560. +On behalf of the beta-testers and other members of the Linux INTERNET
  1561. +community who have helped shape and debug this package I am pleased to
  1562. +announce version 1.3-pl3 of the sysklogd package.
  1563.  
  1564.  This package implements two system log daemons. The syslogd daemon is
  1565.  an enhanced version of the standard Berkeley utility program. This
  1566. @@ -26,6 +26,9 @@
  1567.      * klogd supports on-the-fly kernel address to symbol
  1568.      translations. This requires that a valid kernel symbol map be
  1569.      found at execution.
  1570. +
  1571. +    * klogd also supports debugging of protection faults which occur
  1572. +    in kernel loadable modules.
  1573.  
  1574.      * syslogd has better handling of remote logging capabilities.
  1575.  
  1576. diff -u --new-file --recursive v1.3-2/sysklogd-1.3/MANIFEST ./sysklogd-1.3/MANIFEST
  1577. --- v1.3-2/sysklogd-1.3/MANIFEST    Fri Aug 30 11:19:11 1996
  1578. +++ ./sysklogd-1.3/MANIFEST    Thu Aug 29 10:02:33 1996
  1579. @@ -56,3 +56,7 @@
  1580.  
  1581.  oops_test.c:    A small driver program used in conjunction with the oops
  1582.          module to generate a kernel protection fault.
  1583. +
  1584. +modules.patch:    A patch to the modules-2.0.0 package which provides for
  1585. +        automatic signalling of klogd whenever the kernel module
  1586. +        state changes.
  1587. diff -u --new-file --recursive v1.3-2/sysklogd-1.3/NEWS ./sysklogd-1.3/NEWS
  1588. --- v1.3-2/sysklogd-1.3/NEWS    Fri Aug 30 11:19:10 1996
  1589. +++ ./sysklogd-1.3/NEWS    Fri Aug 30 11:13:28 1996
  1590. @@ -1,3 +1,42 @@
  1591. +Version 1.3 Patch Level 3
  1592. +
  1593. +General. ------------------------------------------------------------------
  1594. +Update to documentation including klogd.8 manpage to reflect new features.
  1595. +
  1596. +Included patch for modules-2.0.0 package to provide support for signalling
  1597. +klogd of changes in kernel module status.
  1598. +
  1599. +klogd ---------------------------------------------------------------------
  1600. +Provided support for signalling klogd to reload static and kernel module
  1601. +symbol information via SIGUSR1 and SIGUSR2.
  1602. +
  1603. +Implemented -p switch to cause a reload of kernel module symbol information
  1604. +whenever a protection fault is detected.
  1605. +
  1606. +Informative message is printed whenever klogd state change occurs.
  1607. +
  1608. +Added -i and -I switches to signal the currently executing klogd daemon
  1609. +to reload symbold information.
  1610. +
  1611. +
  1612. +Version 1.3 Patch Level 2
  1613. +
  1614. +General. ------------------------------------------------------------------
  1615. +Added oops.c and oops_test.c.  Oops.c implements a kernel loadable module
  1616. +which will generate a general protection fault.  The oops_test.c program
  1617. +generates a test program for exercising the loadable module.
  1618. +
  1619. +syslogd ------------------------------------------------------------------
  1620. +Fixed bug resulting in file descriptors being orphaned when syslogd was
  1621. +initialized via signal handler.
  1622. +
  1623. +klogd ---------------------------------------------------------------------
  1624. +Bug fix to prevent errors when reading symbol tables with 64 bit addresses.
  1625. +
  1626. +Added support for debugging of protection faults occuring in kernel
  1627. +loadable modules.
  1628. +
  1629. +
  1630.  Version 1.3 Patch Level 1
  1631.  
  1632.  General. ------------------------------------------------------------------
  1633. @@ -9,7 +48,6 @@
  1634.  
  1635.  Spelling and grammar corrections in the man pages.
  1636.  
  1637. -
  1638.  syslogd ------------------------------------------------------------------
  1639.  Patch to fix parsing of hostnames in syslogd.c.
  1640.  
  1641. @@ -18,7 +56,6 @@
  1642.  
  1643.  Bounds error fixed when setting the file descriptors for UNIX domain
  1644.  sockets.
  1645. -
  1646.  
  1647.  klogd ---------------------------------------------------------------------
  1648.  Error checking and reporting enhanced.  I have a couple of reports
  1649. diff -u --new-file --recursive v1.3-2/sysklogd-1.3/Sysklogd-1.3.lsm ./sysklogd-1.3/Sysklogd-1.3.lsm
  1650. --- v1.3-2/sysklogd-1.3/Sysklogd-1.3.lsm    Tue Feb 27 16:22:57 1996
  1651. +++ ./sysklogd-1.3/Sysklogd-1.3.lsm    Fri Aug 30 10:52:39 1996
  1652. @@ -12,6 +12,8 @@
  1653.          routes them to either output files or to syslogd.  This
  1654.          version of klogd will optionally translate kernel addresses
  1655.          to their symbolic equivalents if provided with a system map.
  1656. +        The klogd daemon also provides support for debugging of
  1657. +        protection faults which occur in kernel loadable modules.
  1658.  Keywords:       logging, remote, kernel, syslogd, proc, daemon, klogd
  1659.  Author:         greg@wind.rmcc.com (Dr. G.W. Wettstein)
  1660.  Maintained-by:  greg@wind.rmcc.com (Dr. G.W. Wettstein)
  1661. diff -u --new-file --recursive v1.3-2/sysklogd-1.3/klogd.8 ./sysklogd-1.3/klogd.8
  1662. --- v1.3-2/sysklogd-1.3/klogd.8    Fri Dec 15 15:06:26 1995
  1663. +++ ./sysklogd-1.3/klogd.8    Fri Aug 30 11:00:56 1996
  1664. @@ -2,6 +2,7 @@
  1665.  .\" May be distributed under the GNU General Public License
  1666.  .\" Sun Jul 30 01:35:55 MET: Martin Schulze: Updates
  1667.  .\" Sun Nov 19 23:22:21 MET: Martin Schulze: Updates
  1668. +.\" Mon Aug 19 09:42:08 CDT 1996: Dr. G.W. Wettstein: Updates
  1669.  .\"
  1670.  .TH KLOGD 8 "24 November 1995" "Version 1.3" "Linux System Administration"
  1671.  .SH NAME
  1672. @@ -16,8 +17,10 @@
  1673.  .RB [ " \-f "
  1674.  .I fname
  1675.  ]
  1676. +.RB [ " \-iI " ]
  1677.  .RB [ " \-n " ]
  1678.  .RB [ " \-o " ]
  1679. +.RB [ " \-p " ]
  1680.  .RB [ " \-s " ]
  1681.  .RB [ " \-k "
  1682.  .I fname
  1683. @@ -41,6 +44,12 @@
  1684.  .BI "\-f " file
  1685.  Log messages to the specified filename rather than to the syslog facility.
  1686.  .TP
  1687. +.BI "\-i \-I"
  1688. +Signal the currently executing klogd daemon.  Both of these switches control
  1689. +the loading/reloading of symbol information.  The \-i switch signals the
  1690. +daemon to reload the kernel module symbols.  The \-I switch signals for a
  1691. +reload of both the static kernel symbols and the kernel module symbols.
  1692. +.TP
  1693.  .B "\-n"
  1694.  Avoid auto-backgrounding. This is needed especially if the
  1695.  .B klogd
  1696. @@ -52,6 +61,12 @@
  1697.  all the messages that are found in the kernel message buffers.  After
  1698.  a single read and log cycle the daemon exits.
  1699.  .TP
  1700. +.B "-p"
  1701. +Enable paranoia.  This option controls when klogd loads kernel module symbol
  1702. +information.  Setting this switch causes klogd to load the kernel module
  1703. +symbol information whenever an Oops string is detected in the kernel message
  1704. +stream.
  1705. +.TP
  1706.  .B "-s"
  1707.  Force \fBklogd\fP to use the system call interface to the kernel message
  1708.  buffers.
  1709. @@ -72,15 +87,15 @@
  1710.  
  1711.  In Linux there are two potential sources of kernel log information: the 
  1712.  .I /proc
  1713. -filesystem and the syscall (sys_syslog) interface, although
  1714. +file system and the syscall (sys_syslog) interface, although
  1715.  ultimately they are one and the same.  Klogd is designed to choose
  1716.  whichever source of information is the most appropriate.  It does this
  1717.  by first checking for the presence of a mounted 
  1718.  .I /proc
  1719. -filesystem. If this is found the 
  1720. +file system. If this is found the 
  1721.  .I /proc/kmsg
  1722.  file is used as the source of kernel log
  1723. -information. If the proc filesystem is not mounted 
  1724. +information. If the proc file system is not mounted 
  1725.  .B klogd
  1726.  uses a
  1727.  system call to obtain kernel messages.  The command line switch
  1728. @@ -163,10 +178,43 @@
  1729.  .fi
  1730.  .PP
  1731.  .SH KERNEL ADDRESS RESOLUTION
  1732. +If the kernel detects an internal error condition a general protection
  1733. +fault will be triggered.  As part of the GPF handling procedure the
  1734. +kernel prints out a status report indicating the state of the
  1735. +processor at the time of the fault.  Included in this display are the
  1736. +contents of the microprocessor's registers, the contents of the kernel
  1737. +stack and a tracing of what functions were being executed at the time
  1738. +of the fault.
  1739. +
  1740. +This information is
  1741. +.B EXTREMELY IMPORTANT
  1742. +in determining what caused the internal error condition.  The
  1743. +difficulty comes when a kernel developer attempts to analyze this
  1744. +information.  The raw numeric information present in the protection
  1745. +fault printout is of very little use to the developers.  This is due
  1746. +to the fact that kernels are not identical and the addresses of
  1747. +variable locations or functions will not be the same in all kernels.
  1748. +In order to correctly diagnose the cause of failure a kernel developer
  1749. +needs to know what specific kernel functions or variable locations
  1750. +were involved in the error.
  1751. +
  1752. +As part of the kernel compilation process a listing is created which
  1753. +specified the address locations of important variables and function in
  1754. +the kernel being compiled.  This listing is saved in a file called
  1755. +System.map in the top of the kernel directory source tree.  Using this
  1756. +listing a kernel developer can determine exactly what the kernel was
  1757. +doing when the error condition occurred.
  1758. +
  1759. +The process of resolving the numeric addresses from the protection
  1760. +fault printout can be done manually or by using the
  1761. +.B ksymoops
  1762. +program which is included in the kernel sources.
  1763. +
  1764. +As a convenience
  1765.  .B klogd
  1766.  will attempt to resolve kernel numeric addresses to their symbolic
  1767. -forms if a kernel symbol table is available at execution time.
  1768. -A symbol table may be specified by using the \fB\-k\fR switch on the
  1769. +forms if a kernel symbol table is available at execution time.  A
  1770. +symbol table may be specified by using the \fB\-k\fR switch on the
  1771.  command line.  If a symbol file is not explicitly specified the
  1772.  following filenames will be tried:
  1773.  
  1774. @@ -192,19 +240,101 @@
  1775.  so that they will be recognized and translated by klogd.  Earlier
  1776.  kernels require a source code patch be applied to the kernel sources.
  1777.  This patch is supplied with the sysklogd sources.
  1778. +
  1779. +The process of analyzing kernel protections faults works very well
  1780. +with a static kernel.  Additional difficulties are encountered when
  1781. +attempting to diagnose errors which occur in loadable kernel modules.
  1782. +Loadable kernel modules are used to implement kernel functionality in
  1783. +a form which can be loaded or unloaded at will.  The use of loadable
  1784. +modules is useful from a debugging standpoint and can also be useful
  1785. +in decreasing the amount of memory required by a kernel.
  1786. +
  1787. +The difficulty with diagnosing errors in loadable modules is due to
  1788. +the dynamic nature of the kernel modules.  When a module is loaded the
  1789. +kernel will allocate memory to hold the module, when the module is
  1790. +unloaded this memory will be returned back to the kernel.  This
  1791. +dynamic memory allocation makes it impossible to produce a map file
  1792. +which details the addresses of the variable and functions in a kernel
  1793. +loadable module.  Without this location map it is not possible for a
  1794. +kernel developer to determine what went wrong if a protection fault
  1795. +involves a kernel module.
  1796. +
  1797. +.B klogd
  1798. +has support for dealing with the problem of diagnosing protection
  1799. +faults in kernel loadable modules.  At program start time or in
  1800. +response to a signal the daemon will interrogate the kernel for a
  1801. +listing of all modules loaded and the addresses in memory they are
  1802. +loaded at.  Individual modules can also register the locations of
  1803. +important functions when the module is loaded.  The addresses of these
  1804. +exported symbols are also determined during this interrogation
  1805. +process.
  1806. +
  1807. +When a protection fault occurs an attempt will be made to resolve
  1808. +kernel addresses from the static symbol table.  If this fails the
  1809. +symbols from the currently loaded modules are examined in an attempt
  1810. +to resolve the addresses.  At the very minimum this allows klogd to
  1811. +indicate which loadable module was responsible for generating the
  1812. +protection fault.  Additional information may be available if the
  1813. +module developer chose to export symbol information from the module.
  1814. +
  1815. +Proper and accurate resolution of addresses in kernel modules requires
  1816. +that
  1817. +.B klogd
  1818. +be informed whenever the kernel module status changes.  The
  1819. +.B \-i
  1820. +and
  1821. +.B \-I
  1822. +switches can be used to signal the currently executing daemon that
  1823. +symbol information be reloaded.  Of most importance to proper
  1824. +resolution of module symbols is the
  1825. +.B \-i
  1826. +switch.  Each time a kernel module is loaded or removed from the
  1827. +kernel the following command should be executed:
  1828. +
  1829. +.nf
  1830. +.I klogd \-i
  1831. +.fi
  1832. +
  1833. +The
  1834. +.B \-p
  1835. +switch can also be used to insure that module symbol information is up
  1836. +to date.  This switch instructs
  1837. +.B klogd
  1838. +to reload the module symbol information whenever a protection fault
  1839. +is detected.  Caution should be used before invoking the program in
  1840. +\'paranoid\' mode.  The stability of the kernel and the operating
  1841. +environment is always under question when a protection fault occurs.
  1842. +Since the klogd daemon must execute system calls in order to read the
  1843. +module symbol information there is the possibility that the system may
  1844. +be too unstable to capture useful information.  A much better policy
  1845. +is to insure that klogd is updated whenever a module is loaded or
  1846. +unloaded.  Having uptodate symbol information loaded increases the
  1847. +probability of properly resolving a protection fault if it should occur.
  1848. +
  1849. +Included in the sysklogd source distribution is a patch to the
  1850. +modules-2.0.0 package which allows the
  1851. +.B insmod,
  1852. +.B rmmod
  1853. +and
  1854. +.B modprobe
  1855. +utilities to automatically signal
  1856. +.B klogd
  1857. +whenever a module is inserted or removed from the kernel.  Using this
  1858. +patch will insure that the symbol information maintained in klogd is
  1859. +always consistent with the current kernel state.
  1860.  .PP
  1861.  .SH SIGNAL HANDLING
  1862.  The 
  1863.  .B klogd
  1864. -will respond to six signals:
  1865. -.BR SIGHUP ", " SIGINT ", " SIGKILL ", " SIGTERM ", " SIGTSTP " and " SIGCONT ". The"
  1866. +will respond to eight signals:
  1867. +.BR SIGHUP ", " SIGINT ", " SIGKILL ", " SIGTERM ", " SIGTSTP ", " SIGUSR1 ", "SIGUSR2 " and " SIGCONT ". The"
  1868.  .BR SIGINT ", " SIGKILL ", " SIGTERM " and " SIGHUP
  1869.  signals will cause the daemon to close its kernel log sources and
  1870.  terminate gracefully.
  1871.  
  1872.  The 
  1873.  .BR SIGTSTP " and " SIGCONT
  1874. -singals are used to start and stop kernel logging. Upon receipt of a 
  1875. +signals are used to start and stop kernel logging. Upon receipt of a 
  1876.  .B SIGTSTP
  1877.  signal the daemon will close its
  1878.  log sources and spin in an idle loop.  Subsequent receipt of a 
  1879. @@ -229,6 +359,26 @@
  1880.  .B LOG_INFO
  1881.  priority
  1882.  documenting the start/stop of logging.
  1883. +
  1884. +The 
  1885. +.BR SIGUSR1 " and " SIGUSR2
  1886. +signals are used to initiate loading/reloading of kernel symbol information.
  1887. +Receipt of the
  1888. +.B SIGUSR1
  1889. +signal will cause the kernel module symbols to be reloaded.  Signaling the
  1890. +daemon with
  1891. +.B SIGUSR2
  1892. +will cause both the static kernel symbols and the kernel module symbols to
  1893. +be reloaded.
  1894. +
  1895. +Provided that the System.map file is placed in an appropriate location the
  1896. +signal of generally greatest usefulness is the
  1897. +.B SIGUSR1
  1898. +signal.  This signal is designed to be used to signal the daemon when kernel
  1899. +modules are loaded/unloaded.  Sending this signal to the daemon after a
  1900. +kernel module state change will insure that proper resolution of symbols will
  1901. +occur if a protection fault occurs in the address space occupied by a kernel
  1902. +module.
  1903.  .LP
  1904.  .SH FILES
  1905.  .PD 0
  1906. @@ -241,7 +391,7 @@
  1907.  The file containing the process id of 
  1908.  .B klogd
  1909.  .TP
  1910. -.I /System.map, /usr/src/linux/System.map
  1911. +.I /boot/System.map, /System.map, /usr/src/linux/System.map
  1912.  Default locations for kernel system maps.
  1913.  .PD
  1914.  .SH BUGS
  1915. diff -u --new-file --recursive v1.3-2/sysklogd-1.3/klogd.c ./sysklogd-1.3/klogd.c
  1916. --- v1.3-2/sysklogd-1.3/klogd.c    Fri Aug 30 11:19:11 1996
  1917. +++ ./sysklogd-1.3/klogd.c    Wed Aug 21 09:15:17 1996
  1918. @@ -141,6 +141,18 @@
  1919.   *    termination cleanup sequence.  This minimizes the potential for
  1920.   *    conflicting pidfiles causing immediate termination at boot time.
  1921.   *    
  1922. + * Wed Aug 21 09:13:03 CDT 1996:  Dr. Wettstein
  1923. + *    Added ability to reload static symbols and kernel module symbols
  1924. + *      under control of SIGUSR1 and SIGUSR2 signals.
  1925. + *
  1926. + *    Added -p switch to select 'paranoid' behavior with respect to the
  1927. + *    loading of kernel module symbols.
  1928. + *
  1929. + *    Informative line now printed whenever a state change occurs due
  1930. + *    to signal reception by the daemon.
  1931. + *
  1932. + *    Added the -i and -I command line switches to signal the currently
  1933. + *    executing daemon.
  1934.   */
  1935.  
  1936.  
  1937. @@ -177,13 +189,15 @@
  1938.          change_state = 0,
  1939.          terminate = 0,
  1940.          caught_TSTP = 0,
  1941. +        reload_symbols = 0,
  1942.          console_log_level = 6;
  1943.  
  1944.  static int    use_syscall = 0,
  1945.          one_shot = 0,
  1946.          NoFork = 0;    /* don't fork - don't run in daemon mode */
  1947.  
  1948. -static char log_buffer[LOG_BUFFER_SIZE];
  1949. +static char    *symfile = (char *) 0,
  1950. +        log_buffer[LOG_BUFFER_SIZE];
  1951.  
  1952.  static FILE *output_file = (FILE *) 0;
  1953.  
  1954. @@ -198,7 +212,10 @@
  1955.  extern void restart(int sig);
  1956.  extern void stop_logging(int sig);
  1957.  extern void stop_daemon(int sig);
  1958. +extern void reload_daemon(int sig);
  1959.  static void Terminate(void);
  1960. +static void SignalDaemon(int);
  1961. +static void ReloadSymbols(void);
  1962.  static void ChangeLogging(void);
  1963.  static enum LOGSRC GetKernelLogSrc(void);
  1964.  static void LogLine(char *ptr, int len);
  1965. @@ -269,6 +286,27 @@
  1966.  }
  1967.  
  1968.  
  1969. +void reload_daemon(sig)
  1970. +
  1971. +     int sig;
  1972. +
  1973. +{
  1974. +    change_state = 1;
  1975. +    reload_symbols = 1;
  1976. +
  1977. +
  1978. +    if ( sig == SIGUSR2 )
  1979. +    {
  1980. +        ++reload_symbols;
  1981. +        signal(SIGUSR2, reload_daemon);
  1982. +    }
  1983. +    else
  1984. +        signal(SIGUSR1, reload_daemon);
  1985. +        
  1986. +    return;
  1987. +}
  1988. +
  1989. +
  1990.  static void Terminate()
  1991.  
  1992.  {
  1993. @@ -282,7 +320,29 @@
  1994.      exit(1);
  1995.  }
  1996.  
  1997. -    
  1998. +static void SignalDaemon(sig)
  1999. +
  2000. +     int sig;
  2001. +
  2002. +{
  2003. +    auto int pid = check_pid(PidFile);
  2004. +
  2005. +    kill(pid, sig);
  2006. +    return;
  2007. +}
  2008. +
  2009. +
  2010. +static void ReloadSymbols()
  2011. +
  2012. +{
  2013. +    if ( reload_symbols > 1 )
  2014. +        InitKsyms(symfile);
  2015. +    InitMsyms();
  2016. +    reload_symbols = change_state = 0;
  2017. +    return;
  2018. +}
  2019. +
  2020. +
  2021.  static void ChangeLogging(void)
  2022.  
  2023.  {
  2024. @@ -290,6 +350,17 @@
  2025.      if ( terminate == 1 )
  2026.          Terminate();
  2027.  
  2028. +    /* Indicate that something is happening. */
  2029. +    Syslog(LOG_INFO, "klogd %s-%s, ---------- state change ----------\n", \
  2030. +           VERSION, PATCHLEVEL);
  2031. +
  2032. +    /* Reload symbols. */
  2033. +    if ( reload_symbols > 0 )
  2034. +    {
  2035. +        ReloadSymbols();
  2036. +        return;
  2037. +    }
  2038. +
  2039.      /* Stop kernel logging. */
  2040.      if ( caught_TSTP == 1 )
  2041.      {
  2042. @@ -566,14 +637,14 @@
  2043.      char *argv[];
  2044.  
  2045.  {
  2046. -    auto int ch, use_output = 0;
  2047. +    auto int    ch,
  2048. +            use_output = 0;
  2049.  
  2050. -    auto char    *symfile = (char *) 0,
  2051. -            *log_level = (char *) 0,
  2052. +    auto char    *log_level = (char *) 0,
  2053.              *output = (char *) 0;
  2054.  
  2055.      /* Parse the command-line. */
  2056. -    while ((ch = getopt(argc, argv, "c:df:k:nosv")) != EOF)
  2057. +    while ((ch = getopt(argc, argv, "c:df:iIk:nopsv")) != EOF)
  2058.          switch((char)ch)
  2059.          {
  2060.              case 'c':        /* Set console message level. */
  2061. @@ -586,6 +657,12 @@
  2062.              output = optarg;
  2063.              use_output++;
  2064.              break;
  2065. +            case 'i':        /* Reload module symbols. */
  2066. +            SignalDaemon(SIGUSR1);
  2067. +            return(0);
  2068. +            case 'I':
  2069. +            SignalDaemon(SIGUSR2);
  2070. +            return(0);
  2071.              case 'k':        /* Kernel symbol file. */
  2072.              symfile = optarg;
  2073.              break;
  2074. @@ -595,6 +672,9 @@
  2075.              case 'o':        /* One-shot mode. */
  2076.              one_shot = 1;
  2077.              break;
  2078. +            case 'p':
  2079. +            SetParanoiaLevel(1);    /* Load symbols on oops. */
  2080. +            break;    
  2081.              case 's':        /* Use syscall interface. */
  2082.              use_syscall = 1;
  2083.              break;
  2084. @@ -682,6 +762,8 @@
  2085.      signal(SIGHUP, stop_daemon);
  2086.      signal(SIGTSTP, stop_logging);
  2087.      signal(SIGCONT, restart);
  2088. +    signal(SIGUSR1, reload_daemon);
  2089. +    signal(SIGUSR2, reload_daemon);
  2090.  
  2091.  
  2092.      /* Open outputs. */
  2093. @@ -704,6 +786,7 @@
  2094.      if ( one_shot )
  2095.      {
  2096.          InitKsyms(symfile);
  2097. +        InitMsyms();
  2098.          if ( (logsrc = GetKernelLogSrc()) == kernel )
  2099.              LogKernelLine();
  2100.          else
  2101. @@ -717,6 +800,7 @@
  2102.  #endif
  2103.      logsrc = GetKernelLogSrc();
  2104.      InitKsyms(symfile);
  2105. +    InitMsyms();
  2106.  
  2107.          /* The main loop. */
  2108.      while (1)
  2109. diff -u --new-file --recursive v1.3-2/sysklogd-1.3/klogd.h ./sysklogd-1.3/klogd.h
  2110. --- v1.3-2/sysklogd-1.3/klogd.h    Fri Aug 30 11:19:11 1996
  2111. +++ ./sysklogd-1.3/klogd.h    Tue Jul 30 10:57:17 1996
  2112. @@ -15,4 +15,5 @@
  2113.  extern int InitKsyms(char *);
  2114.  extern int InitMsyms(void);
  2115.  extern char * ExpandKadds(char *, char *);
  2116. +extern void SetParanoiaLevel(int);
  2117.  extern void Syslog(int priority, char *fmt, ...);
  2118. diff -u --new-file --recursive v1.3-2/sysklogd-1.3/ksym.c ./sysklogd-1.3/ksym.c
  2119. --- v1.3-2/sysklogd-1.3/ksym.c    Fri Aug 30 11:19:12 1996
  2120. +++ ./sysklogd-1.3/ksym.c    Wed Aug 21 09:19:14 1996
  2121. @@ -62,6 +62,16 @@
  2122.   *    Added patch from beta-testers to allow for reading of both
  2123.   *    ELF and a.out map files.
  2124.   *
  2125. + * Wed Aug 21 09:15:49 CDT 1996:  Dr. Wettstein
  2126. + *    Reloading of kernel module symbols is now turned on by the
  2127. + *    SetParanoiaLevel function.  The default behavior is to NOT reload
  2128. + *    the kernel module symbols when a protection fault is detected.
  2129. + *
  2130. + *    Added support for freeing of the current kernel module symbols.
  2131. + *    This was necessary to support reloading of the kernel module symbols.
  2132. + *
  2133. + *    When a matching static symbol table is loaded the kernel version
  2134. + *    number is printed.
  2135.   */
  2136.  
  2137.  
  2138. @@ -83,6 +93,8 @@
  2139.  };
  2140.  
  2141.  static int num_syms = 0;
  2142. +static int i_am_paranoid = 0;
  2143. +static char vstring[12];
  2144.  static struct sym_table *sym_array = (struct sym_table *) 0;
  2145.  
  2146.  static char *system_maps[] =
  2147. @@ -108,6 +120,7 @@
  2148.  static char * FindSymbolFile(void);
  2149.  static int AddSymbol(unsigned long, char*);
  2150.  static char * LookupSymbol(unsigned long, struct symbol *);
  2151. +static void FreeSymbols(void);
  2152.  static int CheckVersion(char *);
  2153.  
  2154.  
  2155. @@ -144,6 +157,11 @@
  2156.      auto FILE *sym_file;
  2157.  
  2158.  
  2159. +    /* Check and make sure that we are starting with a clean slate. */
  2160. +    if ( num_syms > 0 )
  2161. +        FreeSymbols();
  2162. +
  2163. +
  2164.      /*
  2165.       * Search for and open the file containing the kernel symbols.
  2166.       */
  2167. @@ -222,7 +240,7 @@
  2168.          break;
  2169.          
  2170.          case 1:
  2171. -        Syslog(LOG_INFO, "Symbols match kernel version.");
  2172. +        Syslog(LOG_INFO, "Symbols match kernel version %s.", vstring);
  2173.          break;
  2174.      }
  2175.          
  2176. @@ -397,8 +415,6 @@
  2177.      
  2178.  
  2179.  {
  2180. -    auto char vstring[6];
  2181. -
  2182.      auto int    vnum,
  2183.              major,
  2184.              minor,
  2185. @@ -423,16 +439,15 @@
  2186.       * things out by decoding the version string into its component
  2187.       * parts.
  2188.       */
  2189. -    memset(vstring, '\0', sizeof(vstring));
  2190. -    strncpy(vstring, version + strlen(prefix), sizeof(vstring)-1);
  2191. -    vnum = atoi(vstring);
  2192. +    vnum = atoi(version + strlen(prefix));
  2193.      major = vnum / 65536;
  2194.      vnum -= (major * 65536);
  2195.      minor = vnum / 256;
  2196.      patch = vnum - (minor * 256);
  2197.      if ( debugging )
  2198.          fprintf(stderr, "Version string = %s, Major = %d, " \
  2199. -               "Minor = %d, Patch = %d.\n", vstring, major, minor, \
  2200. +               "Minor = %d, Patch = %d.\n", version +
  2201. +               strlen(prefix), major, minor, \
  2202.                 patch);
  2203.      sprintf(vstring, "%d.%d.%d", major, minor, patch);
  2204.  
  2205. @@ -558,6 +573,37 @@
  2206.  
  2207.  
  2208.  /**************************************************************************
  2209. + * Function:    FreeSymbols
  2210. + *
  2211. + * Purpose:    This function is responsible for freeing all memory which
  2212. + *        has been allocated to hold the static symbol table.  It
  2213. + *        also initializes the symbol count and in general prepares
  2214. + *        for a re-read of a static symbol table.
  2215. + *
  2216. + * Arguements:  void
  2217. + *
  2218. + * Return:    void
  2219. + **************************************************************************/
  2220. +
  2221. +static void FreeSymbols()
  2222. +
  2223. +{
  2224. +    auto int lp;
  2225. +
  2226. +    /* Free each piece of memory allocated for symbol names. */
  2227. +    for(lp= 0; lp < num_syms; ++lp)
  2228. +        free(sym_array[lp].name);
  2229. +
  2230. +    /* Whack the entire array and initialize everything. */
  2231. +    free(sym_array);
  2232. +    sym_array = (struct sym_table *) 0;
  2233. +    num_syms = 0;
  2234. +
  2235. +    return;
  2236. +}
  2237. +
  2238. +
  2239. +/**************************************************************************
  2240.   * Function:    LogExpanded
  2241.   *
  2242.   * Purpose:    This function is responsible for logging a kernel message
  2243. @@ -610,7 +656,8 @@
  2244.       * kernel whenever a module is loaded or unloaded.  I am
  2245.       * open for patches.
  2246.       */
  2247. -    if ( (strstr(line, "Oops:") != (char *) 0) && !InitMsyms() )
  2248. +    if ( i_am_paranoid &&
  2249. +         (strstr(line, "Oops:") != (char *) 0) && !InitMsyms() )
  2250.          Syslog(LOG_WARNING, "Cannot load kernel module symbols.\n");
  2251.      
  2252.  
  2253. @@ -670,6 +717,30 @@
  2254.      if ( debugging )
  2255.          fprintf(stderr, "Expanded line: %s\n", el);
  2256.      return(el);
  2257. +}
  2258. +
  2259. +
  2260. +/**************************************************************************
  2261. + * Function:    SetParanoiaLevel
  2262. + *
  2263. + * Purpose:    This function is an interface function for setting the
  2264. + *        mode of loadable module symbol lookups.  Probably overkill
  2265. + *        but it does slay another global variable.
  2266. + *
  2267. + * Arguements:    (int) level
  2268. + *
  2269. + *        level:->    The amount of paranoia which is to be
  2270. + *                present when resolving kernel exceptions.
  2271. + * Return:    void
  2272. + **************************************************************************/
  2273. +
  2274. +extern void SetParanoiaLevel(level)
  2275. +
  2276. +    int level;
  2277. +
  2278. +{
  2279. +    i_am_paranoid = level;
  2280. +    return;
  2281.  }
  2282.  
  2283.  
  2284. diff -u --new-file --recursive v1.3-2/sysklogd-1.3/ksym_mod.c ./sysklogd-1.3/ksym_mod.c
  2285. --- v1.3-2/sysklogd-1.3/ksym_mod.c    Fri Aug 30 11:19:12 1996
  2286. +++ ./sysklogd-1.3/ksym_mod.c    Fri Aug 23 11:45:27 1996
  2287. @@ -37,6 +37,15 @@
  2288.   * possible.
  2289.   *
  2290.   * At least that is the plan.
  2291. + *
  2292. + * Wed Aug 21 09:20:09 CDT 1996:  Dr. Wettstein
  2293. + *    The situation where no module support has been compiled into a
  2294. + *    kernel is now detected.  An informative message is output indicating
  2295. + *    that the kernel has no loadable module support whenever kernel
  2296. + *    module symbols are loaded.
  2297. + *
  2298. + *    An informative message is printed indicating the number of kernel
  2299. + *    modules and the number of symbols loaded from these modules.
  2300.   */
  2301.  
  2302.  
  2303. @@ -65,7 +74,7 @@
  2304.   */
  2305.  #define __LIBRARY__
  2306.  #include <linux/unistd.h>
  2307. -# define __NR_getsyms __NR_get_kernel_syms
  2308. +#define __NR_getsyms __NR_get_kernel_syms
  2309.  _syscall1(int, getsyms, struct kernel_sym *, syms);
  2310.  #undef __LIBRARY__
  2311.  extern int getsyms(struct kernel_sym *);
  2312. @@ -87,7 +96,7 @@
  2313.      struct module module;
  2314.  };
  2315.  
  2316. -static int num_modules;
  2317. +static int num_modules = 0;
  2318.  struct Module *sym_array_modules = (struct Module *) 0;
  2319.  
  2320.  static int have_modules = 0;
  2321. @@ -132,9 +141,8 @@
  2322.                  *p;
  2323.  
  2324.  
  2325. -    /* Init the symbol table if one exists. */
  2326. -    if ( num_modules > 0 )
  2327. -        FreeModules();
  2328. +    /* Initialize the kernel module symbol table. */
  2329. +    FreeModules();
  2330.  
  2331.  
  2332.      /*
  2333. @@ -153,7 +161,16 @@
  2334.       *
  2335.       * Bummer.
  2336.       */
  2337. -    rtn = getsyms((struct kernel_sym *) 0);
  2338. +    if ( (rtn = getsyms((struct kernel_sym *) 0)) < 0 )
  2339. +    {
  2340. +        if ( errno == ENOSYS )
  2341. +            Syslog(LOG_INFO, "No module symbols loaded - "
  2342. +                   "kernel modules not enabled.\n");
  2343. +        else
  2344. +            Syslog(LOG_ERR, "Error loading kernel symbols " \
  2345. +                   "- %s\n", strerror(errno));
  2346. +        return(0);
  2347. +    }
  2348.      if ( debugging )
  2349.          fprintf(stderr, "Loading kernel module symbols - "
  2350.              "Size of table: %d\n", rtn);
  2351. @@ -162,12 +179,16 @@
  2352.                            sizeof(struct kernel_sym));
  2353.      if ( ksym_table == (struct kernel_sym *) 0 )
  2354.      {
  2355. -        Syslog(LOG_WARNING, " Failed memory allocation for kernel "
  2356. +        Syslog(LOG_WARNING, " Failed memory allocation for kernel " \
  2357.                 "symbol table.\n");
  2358.          return(0);
  2359.      }
  2360. -    if ( (rtn = getsyms(ksym_table)) == 0 )
  2361. -        Syslog(LOG_WARNING, "Kernel symbol read returned 0\n");
  2362. +    if ( (rtn = getsyms(ksym_table)) < 0 )
  2363. +    {
  2364. +        Syslog(LOG_WARNING, "Error reading kernel symbols - %s\n", \
  2365. +               strerror(errno));
  2366. +        return(0);
  2367. +    }
  2368.  
  2369.  
  2370.      /*
  2371. @@ -189,8 +210,9 @@
  2372.      }
  2373.  
  2374.      /* Sort the symbol tables in each module. */
  2375. -    for (tmp= 0; tmp < num_modules; ++tmp)
  2376. +    for (rtn = tmp= 0; tmp < num_modules; ++tmp)
  2377.      {
  2378. +        rtn += sym_array_modules[tmp].num_syms;
  2379.          if ( sym_array_modules[tmp].num_syms < 2 )
  2380.              continue;
  2381.          qsort(sym_array_modules[tmp].sym_array, \
  2382. @@ -198,6 +220,12 @@
  2383.                sizeof(struct sym_table), symsort);
  2384.      }
  2385.  
  2386. +    if ( rtn == 0 )
  2387. +        Syslog(LOG_INFO, "No module symbols loaded.");
  2388. +    else
  2389. +        Syslog(LOG_INFO, "Loaded %d %s from %d module%s", rtn, \
  2390. +               (rtn == 1) ? "symbol" : "symbols", \
  2391. +               num_modules, (num_modules == 1) ? "." : "s.");
  2392.      free(ksym_table);
  2393.      return(1);
  2394.  }
  2395. @@ -241,7 +269,13 @@
  2396.      auto struct Module *mp;
  2397.  
  2398.  
  2399. -    for (nmods= 0; nmods <num_modules; ++nmods)
  2400. +    /* Check to see if the module symbol tables need to be cleared. */
  2401. +    have_modules = 0;
  2402. +    if ( num_modules == 0 )
  2403. +        return;
  2404. +
  2405. +
  2406. +    for (nmods= 0; nmods < num_modules; ++nmods)
  2407.      {
  2408.          mp = &sym_array_modules[nmods];
  2409.          if ( mp->num_syms == 0 )
  2410. @@ -254,7 +288,7 @@
  2411.  
  2412.      free(sym_array_modules);
  2413.      sym_array_modules = (struct Module *) 0;
  2414. -    have_modules = num_modules = 0;
  2415. +    num_modules = 0;
  2416.      return;
  2417.  }
  2418.  
  2419. @@ -296,6 +330,7 @@
  2420.       */
  2421.      if ( symbol[0] == '#' )
  2422.      {
  2423. +
  2424.          if ( symbol[1] == '\0' )
  2425.          {
  2426.              /*
  2427. @@ -307,7 +342,6 @@
  2428.              have_modules = 1;
  2429.              return(1);
  2430.          }
  2431. -
  2432.          /* Allocate space for the module. */
  2433.          sym_array_modules = (struct Module *) \
  2434.              realloc(sym_array_modules, \
  2435. @@ -584,4 +618,19 @@
  2436.      FreeModules();
  2437.      return(0);
  2438.  }
  2439. +
  2440. +extern void Syslog(int priority, char *fmt, ...)
  2441. +
  2442. +{
  2443. +    va_list ap;
  2444. +
  2445. +    va_start(ap, fmt);
  2446. +    fprintf(stdout, "Pr: %d, ", priority);
  2447. +    vfprintf(stdout, fmt, ap);
  2448. +    va_end(ap);
  2449. +    fputc('\n', stdout);
  2450. +
  2451. +    return;
  2452. +}
  2453. +
  2454.  #endif
  2455. diff -u --new-file --recursive v1.3-2/sysklogd-1.3/modutils.patch ./sysklogd-1.3/modutils.patch
  2456. --- v1.3-2/sysklogd-1.3/modutils.patch    Wed Dec 31 18:00:00 1969
  2457. +++ ./sysklogd-1.3/modutils.patch    Thu Aug 29 10:00:32 1996
  2458. @@ -0,0 +1,65 @@
  2459. +diff -u --new-file --recursive base/modules-2.0.0/depmod/modprobe.c ./modules-2.0.0/depmod/modprobe.c
  2460. +--- base/modules-2.0.0/depmod/modprobe.c    Mon Jun 10 05:29:08 1996
  2461. ++++ ./modules-2.0.0/depmod/modprobe.c    Thu Aug 29 09:58:01 1996
  2462. +@@ -233,6 +233,13 @@
  2463. +     verbose ("\r\t%s\n\t\t",cmd);
  2464. +     int ret = system(cmd);
  2465. + #endif
  2466. ++    if ( fork() == 0 )
  2467. ++    {
  2468. ++        /* Child process. */
  2469. ++        if ( execlp("klogd", "klogd", "-i", (char *) 0)  < 0 )
  2470. ++            fprintf(stderr, "Failure in signaling klogd.\n");
  2471. ++        exit(0);
  2472. ++    }
  2473. +     return ret;
  2474. + }
  2475. + /*
  2476. +diff -u --new-file --recursive base/modules-2.0.0/insmod/insmod.c ./modules-2.0.0/insmod/insmod.c
  2477. +--- base/modules-2.0.0/insmod/insmod.c    Mon Jun 10 06:42:25 1996
  2478. ++++ ./modules-2.0.0/insmod/insmod.c    Thu Aug 29 09:56:53 1996
  2479. +@@ -253,6 +253,18 @@
  2480. +     ++n_stringpatches;
  2481. + }
  2482. ++
  2483. ++void signal_klogd() {
  2484. ++    if ( fork() == 0 )
  2485. ++    {
  2486. ++        if ( execlp("klogd", "klogd", "-i", (char *) 0)  < 0 )
  2487. ++            fprintf(stderr, "Failure in signaling klogd.\n");
  2488. ++        exit(0);
  2489. ++    }
  2490. ++    return;
  2491. ++}
  2492. ++
  2493. ++
  2494. + int main(int argc, char **argv)
  2495. + {
  2496. +     FILE *fp;
  2497. +@@ -983,6 +995,8 @@
  2498. +             symvalue(sp) + addr, symtype, symname(sp));
  2499. +     }
  2500. ++    signal_klogd();
  2501. ++
  2502. +     if (nksyms > 0)
  2503. +         free(ksymtab); /* it has done its job */
  2504. +@@ -1292,6 +1306,7 @@
  2505. +             --argc;
  2506. +             ++argv;
  2507. +         }
  2508. ++        signal_klogd();
  2509. +         return errors;
  2510. +     }
  2511. +     /* else recursive removal */
  2512. +@@ -1353,6 +1368,8 @@
  2513. +             break;
  2514. +         }
  2515. +     }
  2516. ++
  2517. ++    signal_klogd();
  2518. +     return errors;
  2519. + }
  2520. diff -u --new-file --recursive v1.3-2/sysklogd-1.3/version.h ./sysklogd-1.3/version.h
  2521. --- v1.3-2/sysklogd-1.3/version.h    Fri Aug 30 11:19:13 1996
  2522. +++ ./sysklogd-1.3/version.h    Fri Jul 12 13:03:12 1996
  2523. @@ -1,2 +1,2 @@
  2524.  #define VERSION "1.3"
  2525. -#define PATCHLEVEL "2"
  2526. +#define PATCHLEVEL "3"
  2527. Cut here to complete separating patch 3. ----------------------------------
  2528.  
  2529. }-- End of excerpt from "John M. Fisk"
  2530.  
  2531. As always,
  2532. Dr. G.W. Wettstein           Oncology Research Div. Computing Facility
  2533. Roger Maris Cancer Center    INTERNET: greg@wind.rmcc.com
  2534. 820 4th St. N.
  2535. Fargo, ND  58122
  2536. Phone: 701-234-7556
  2537. ------------------------------------------------------------------------------
  2538. "A computer without Windows is like a fish without a bicycle."
  2539.                 -- Chris Woods
  2540.  
  2541.